Changeset bdfc032 for benchmark/bench.h


Ignore:
Timestamp:
Feb 4, 2020, 11:35:26 AM (4 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
eef8dfb
Parents:
aefb247 (diff), 4f7b418 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' into dkobets-vector

File:
1 edited

Legend:

Unmodified
Added
Removed
  • benchmark/bench.h

    raefb247 rbdfc032  
    55#endif
    66        #include <stdlib.h>
    7         #include <unistd.h>                                     // sysconf
     7        #include <stdint.h>                             // uint64_t
     8        #include <unistd.h>                             // sysconf
    89#if ! defined(__cforall)
    910        #include <time.h>
     
    1516
    1617
    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
     18static 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
    3223
    3324#ifndef BENCH_N
    34 #define BENCH_N 500 //10000000
     25#define BENCH_N 10000000
    3526#endif
    3627
     28size_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
    3736#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;            \
    4438        StartTime = bench_time();               \
    45         statement;                                      \
     39        statement;                              \
    4640        EndTime = bench_time();                 \
    47         double output =         \
    48             (double)( EndTime - StartTime ) / n;
     41        double output = (double)( EndTime - StartTime ) / times;
     42
    4943
    5044#if defined(__cforall)
     
    5347}
    5448#endif
     49#if defined(__U_CPLUSPLUS__)
     50unsigned int uDefaultPreemption() {
     51        return 0;
     52}
     53#endif
Note: See TracChangeset for help on using the changeset viewer.