source:
benchmark/bench.h@
1c35c78
| Last change on this file since 1c35c78 was 73abe95, checked in by , 7 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 |
| [9d32bc8] | 8 | #if ! defined(__cforall) |
| 9 | #include <time.h> | |
| 10 | #include <sys/time.h> | |
| 11 | #else | |
| [8cb6fcd] | 12 | } |
| [73abe95] | 13 | #include <time.hfa> |
| [d67cdb7] | 14 | #endif |
| [8cb6fcd] | 15 | |
| [d8548e2] | 16 | |
| [399a908] | 17 | static inline unsigned long long int bench_time() { |
| [d67cdb7] | 18 | struct timespec ts; |
| [8cb6fcd] | 19 | clock_gettime( |
| 20 | #if defined( __linux__ ) | |
| 21 | CLOCK_THREAD_CPUTIME_ID, | |
| 22 | #elif defined( __freebsd__ ) | |
| 23 | CLOCK_PROF, | |
| 24 | #elif defined( __solaris__ ) | |
| 25 | CLOCK_HIGHRES, | |
| 26 | #else | |
| 27 | #error uC++ : internal error, unsupported architecture | |
| 28 | #endif | |
| 29 | &ts ); | |
| 30 | return 1000000000LL * ts.tv_sec + ts.tv_nsec; | |
| 31 | } // Time | |
| 32 | ||
| [034165a] | 33 | #ifndef BENCH_N |
| 34 | #define BENCH_N 500 //10000000 | |
| [7286a40] | 35 | #endif |
| 36 | ||
| [034165a] | 37 | #define BENCH(statement, output) \ |
| [b7170a64] | 38 | size_t n = BENCH_N; \ |
| 39 | if( argc > 2 ) return 1; \ | |
| 40 | if( argc == 2 ) { \ | |
| 41 | n = atoi(argv[1]); \ | |
| 42 | } \ | |
| [034165a] | 43 | long long int StartTime, EndTime; \ |
| [9d32bc8] | 44 | StartTime = bench_time(); \ |
| [b7170a64] | 45 | statement; \ |
| [9d32bc8] | 46 | EndTime = bench_time(); \ |
| [034165a] | 47 | unsigned long long int output = \ |
| [b7170a64] | 48 | ( EndTime - StartTime ) / n; |
| [034165a] | 49 | |
| [9d32bc8] | 50 | #if defined(__cforall) |
| [399a908] | 51 | Duration default_preemption() { |
| [7286a40] | 52 | return 0; |
| [8ad6533] | 53 | } |
| [9d32bc8] | 54 | #endif |
Note:
See TracBrowser
for help on using the repository browser.