Changes in benchmark/bench.h [846c026:dc33b5b]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
benchmark/bench.h
r846c026 rdc33b5b 5 5 #endif 6 6 #include <stdlib.h> 7 #include <stdint.h> // uint64_t 8 #include <unistd.h> // sysconf 7 #include <unistd.h> // sysconf 9 8 #if ! defined(__cforall) 10 9 #include <time.h> … … 16 15 17 16 18 static inline uint64_t bench_time() { 19 struct timespec ts; 20 clock_gettime( CLOCK_THREAD_CPUTIME_ID, &ts ); 21 return 1000000000LL * ts.tv_sec + ts.tv_nsec; 22 } // bench_time 17 static inline unsigned long long int bench_time() { 18 struct timespec ts; 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 23 32 24 33 #ifndef BENCH_N 25 #define BENCH_N 1000000034 #define BENCH_N 500 //10000000 26 35 #endif 27 36 28 size_t times = BENCH_N;29 30 #define BENCH_START() \31 if ( argc > 2 ) exit( EXIT_FAILURE ); \32 if ( argc == 2 ) { \33 times = atoi( argv[1] ); \34 }35 36 37 #define BENCH(statement, output) \ 37 uint64_t StartTime, EndTime; \ 38 size_t n = BENCH_N; \ 39 if( argc > 2 ) return 1; \ 40 if( argc == 2 ) { \ 41 n = atoi(argv[1]); \ 42 } \ 43 long long int StartTime, EndTime; \ 38 44 StartTime = bench_time(); \ 39 statement; \45 statement; \ 40 46 EndTime = bench_time(); \ 41 double output = (double)( EndTime - StartTime ) / times;42 47 double output = \ 48 (double)( EndTime - StartTime ) / n; 43 49 44 50 #if defined(__cforall) … … 47 53 } 48 54 #endif 49 #if defined(__U_CPLUSPLUS__)50 unsigned int uDefaultPreemption() {51 return 0;52 }53 #endif
Note:
See TracChangeset
for help on using the changeset viewer.