Changeset 846c026
- Timestamp:
- Jan 7, 2020, 3:44:09 PM (5 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- b4107c8
- Parents:
- 90cb6f7
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
benchmark/bench.h
r90cb6f7 r846c026 5 5 #endif 6 6 #include <stdlib.h> 7 #include <unistd.h> // sysconf 7 #include <stdint.h> // uint64_t 8 #include <unistd.h> // sysconf 8 9 #if ! defined(__cforall) 9 10 #include <time.h> … … 15 16 16 17 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 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 32 23 33 24 #ifndef BENCH_N 34 #define BENCH_N 500 //1000000025 #define BENCH_N 10000000 35 26 #endif 36 27 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 37 36 #define BENCH(statement, output) \ 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; \ 37 uint64_t StartTime, EndTime; \ 44 38 StartTime = bench_time(); \ 45 statement; 39 statement; \ 46 40 EndTime = bench_time(); \ 47 double output = \48 (double)( EndTime - StartTime ) / n; 41 double output = (double)( EndTime - StartTime ) / times; 42 49 43 50 44 #if defined(__cforall) … … 53 47 } 54 48 #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.