ADT
        arm-eh
        ast-experimental
        enum
        forall-pointer-decay
        jacob/cs343-translation
        new-ast
        new-ast-unique-expr
        pthread-emulation
        qualifiedEnum
      
      
        
          | Last change
 on this file since 566fde0 was             846c026, checked in by Peter A. Buhr <pabuhr@…>, 6 years ago | 
        
          | 
add BENCH_START to handle comandline parameters
 | 
        
          | 
              
Property                 mode
 set to                 100644 | 
        
          | File size:
            988 bytes | 
      
      
| Line |  | 
|---|
| 1 | #pragma once | 
|---|
| 2 |  | 
|---|
| 3 | #if defined(__cforall) | 
|---|
| 4 | extern "C" { | 
|---|
| 5 | #endif | 
|---|
| 6 | #include <stdlib.h> | 
|---|
| 7 | #include <stdint.h>                             // uint64_t | 
|---|
| 8 | #include <unistd.h>                             // sysconf | 
|---|
| 9 | #if ! defined(__cforall) | 
|---|
| 10 | #include <time.h> | 
|---|
| 11 | #include <sys/time.h> | 
|---|
| 12 | #else | 
|---|
| 13 | } | 
|---|
| 14 | #include <time.hfa> | 
|---|
| 15 | #endif | 
|---|
| 16 |  | 
|---|
| 17 |  | 
|---|
| 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 | 
|---|
| 23 |  | 
|---|
| 24 | #ifndef BENCH_N | 
|---|
| 25 | #define BENCH_N 10000000 | 
|---|
| 26 | #endif | 
|---|
| 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 |  | 
|---|
| 36 | #define BENCH(statement, output)                \ | 
|---|
| 37 | uint64_t StartTime, EndTime;            \ | 
|---|
| 38 | StartTime = bench_time();               \ | 
|---|
| 39 | statement;                              \ | 
|---|
| 40 | EndTime = bench_time();                 \ | 
|---|
| 41 | double output = (double)( EndTime - StartTime ) / times; | 
|---|
| 42 |  | 
|---|
| 43 |  | 
|---|
| 44 | #if defined(__cforall) | 
|---|
| 45 | Duration default_preemption() { | 
|---|
| 46 | return 0; | 
|---|
| 47 | } | 
|---|
| 48 | #endif | 
|---|
| 49 | #if defined(__U_CPLUSPLUS__) | 
|---|
| 50 | unsigned int uDefaultPreemption() { | 
|---|
| 51 | return 0; | 
|---|
| 52 | } | 
|---|
| 53 | #endif | 
|---|
       
      
  Note:
 See   
TracBrowser
 for help on using the repository browser.