source: benchmark/bench.h @ 846c026

arm-ehjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-expr
Last change on this file since 846c026 was 846c026, checked in by Peter A. Buhr <pabuhr@…>, 2 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)
4extern "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
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
23
24#ifndef BENCH_N
25#define BENCH_N 10000000
26#endif
27
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
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)
45Duration default_preemption() {
46        return 0;
47}
48#endif
49#if defined(__U_CPLUSPLUS__)
50unsigned int uDefaultPreemption() {
51        return 0;
52}
53#endif
Note: See TracBrowser for help on using the repository browser.