source: benchmark/bench.h @ 3381ed7

ADTarm-ehast-experimentalenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change on this file since 3381ed7 was 846c026, checked in by Peter A. Buhr <pabuhr@…>, 5 years ago

add BENCH_START to handle comandline parameters

  • Property mode set to 100644
File size: 988 bytes
RevLine 
[8cb6fcd]1#pragma once
2
[0cf5b79]3#if defined(__cforall)
[8cb6fcd]4extern "C" {
[d67cdb7]5#endif
[034165a]6        #include <stdlib.h>
[846c026]7        #include <stdint.h>                             // uint64_t
8        #include <unistd.h>                             // sysconf
[9d32bc8]9#if ! defined(__cforall)
10        #include <time.h>
11        #include <sys/time.h>
12#else
[8cb6fcd]13}
[73abe95]14#include <time.hfa>
[d67cdb7]15#endif
[8cb6fcd]16
[d8548e2]17
[846c026]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
[8cb6fcd]23
[034165a]24#ifndef BENCH_N
[846c026]25#define BENCH_N 10000000
[7286a40]26#endif
27
[846c026]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
[034165a]36#define BENCH(statement, output)                \
[846c026]37        uint64_t StartTime, EndTime;            \
[9d32bc8]38        StartTime = bench_time();               \
[846c026]39        statement;                              \
[9d32bc8]40        EndTime = bench_time();                 \
[846c026]41        double output = (double)( EndTime - StartTime ) / times;
42
[034165a]43
[9d32bc8]44#if defined(__cforall)
[399a908]45Duration default_preemption() {
[7286a40]46        return 0;
[8ad6533]47}
[9d32bc8]48#endif
[846c026]49#if defined(__U_CPLUSPLUS__)
50unsigned int uDefaultPreemption() {
51        return 0;
52}
53#endif
Note: See TracBrowser for help on using the repository browser.