Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • benchmark/bench.h

    r846c026 rdc33b5b  
    55#endif
    66        #include <stdlib.h>
    7         #include <stdint.h>                             // uint64_t
    8         #include <unistd.h>                             // sysconf
     7        #include <unistd.h>                                     // sysconf
    98#if ! defined(__cforall)
    109        #include <time.h>
     
    1615
    1716
    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
     17static 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
    2332
    2433#ifndef BENCH_N
    25 #define BENCH_N 10000000
     34#define BENCH_N 500 //10000000
    2635#endif
    2736
    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 
    3637#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;       \
    3844        StartTime = bench_time();               \
    39         statement;                              \
     45        statement;                                      \
    4046        EndTime = bench_time();                 \
    41         double output = (double)( EndTime - StartTime ) / times;
    42 
     47        double output =         \
     48            (double)( EndTime - StartTime ) / n;
    4349
    4450#if defined(__cforall)
     
    4753}
    4854#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.