source:
src/benchmark/bench.h@
5f61546
| Last change on this file since 5f61546 was d8548e2, checked in by , 8 years ago | |
|---|---|
|
|
| File size: 1.0 KB | |
| Rev | Line | |
|---|---|---|
| [8cb6fcd] | 1 | #pragma once |
| 2 | ||
| [0cf5b79] | 3 | #if defined(__cforall) |
| [8cb6fcd] | 4 | extern "C" { |
| [d67cdb7] | 5 | #endif |
| [034165a] | 6 | #include <stdlib.h> |
| [8cb6fcd] | 7 | #include <unistd.h> // sysconf |
| 8 | #include <sys/times.h> // times | |
| 9 | #include <time.h> | |
| [0cf5b79] | 10 | #if defined(__cforall) |
| [8cb6fcd] | 11 | } |
| [d8548e2] | 12 | #include <bits/cfatime.h> |
| [d67cdb7] | 13 | #endif |
| [8cb6fcd] | 14 | |
| [d8548e2] | 15 | |
| [d67cdb7] | 16 | static inline unsigned long long int Time() { |
| 17 | struct timespec ts; | |
| [8cb6fcd] | 18 | clock_gettime( |
| 19 | #if defined( __linux__ ) | |
| 20 | CLOCK_THREAD_CPUTIME_ID, | |
| 21 | #elif defined( __freebsd__ ) | |
| 22 | CLOCK_PROF, | |
| 23 | #elif defined( __solaris__ ) | |
| 24 | CLOCK_HIGHRES, | |
| 25 | #else | |
| 26 | #error uC++ : internal error, unsupported architecture | |
| 27 | #endif | |
| 28 | &ts ); | |
| 29 | return 1000000000LL * ts.tv_sec + ts.tv_nsec; | |
| 30 | } // Time | |
| 31 | ||
| [034165a] | 32 | #ifndef BENCH_N |
| 33 | #define BENCH_N 500 //10000000 | |
| [7286a40] | 34 | #endif |
| 35 | ||
| [034165a] | 36 | #define BENCH(statement, output) \ |
| [b7170a64] | 37 | size_t n = BENCH_N; \ |
| 38 | if( argc > 2 ) return 1; \ | |
| 39 | if( argc == 2 ) { \ | |
| 40 | n = atoi(argv[1]); \ | |
| 41 | } \ | |
| [034165a] | 42 | long long int StartTime, EndTime; \ |
| [b7170a64] | 43 | StartTime = Time(); \ |
| 44 | statement; \ | |
| 45 | EndTime = Time(); \ | |
| [034165a] | 46 | unsigned long long int output = \ |
| [b7170a64] | 47 | ( EndTime - StartTime ) / n; |
| [034165a] | 48 | |
| [d8548e2] | 49 | __cfa_time_t default_preemption() { |
| [7286a40] | 50 | return 0; |
| 51 | } |
Note:
See TracBrowser
for help on using the repository browser.