source: benchmark/bench.h @ f1ec88a

ADTarm-ehast-experimentalcleanup-dtorsenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change on this file since f1ec88a was 73abe95, checked in by Thierry Delisle <tdelisle@…>, 6 years ago

Replace extension-less headers with .hfa

  • Property mode set to 100644
File size: 1.0 KB
RevLine 
[8cb6fcd]1#pragma once
2
[0cf5b79]3#if defined(__cforall)
[8cb6fcd]4extern "C" {
[d67cdb7]5#endif
[034165a]6        #include <stdlib.h>
[8cb6fcd]7        #include <unistd.h>                                     // sysconf
[9d32bc8]8#if ! defined(__cforall)
9        #include <time.h>
10        #include <sys/time.h>
11#else
[8cb6fcd]12}
[73abe95]13#include <time.hfa>
[d67cdb7]14#endif
[8cb6fcd]15
[d8548e2]16
[399a908]17static inline unsigned long long int bench_time() {
[d67cdb7]18    struct timespec ts;
[8cb6fcd]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
32
[034165a]33#ifndef BENCH_N
34#define BENCH_N 500 //10000000
[7286a40]35#endif
36
[034165a]37#define BENCH(statement, output)                \
[b7170a64]38        size_t n = BENCH_N;                     \
39        if( argc > 2 ) return 1;                \
40        if( argc == 2 ) {                               \
41                n = atoi(argv[1]);              \
42        }                                               \
[034165a]43        long long int StartTime, EndTime;       \
[9d32bc8]44        StartTime = bench_time();               \
[b7170a64]45        statement;                                      \
[9d32bc8]46        EndTime = bench_time();                 \
[034165a]47        unsigned long long int output =         \
[b7170a64]48        ( EndTime - StartTime ) / n;
[034165a]49
[9d32bc8]50#if defined(__cforall)
[399a908]51Duration default_preemption() {
[7286a40]52        return 0;
[8ad6533]53}
[9d32bc8]54#endif
Note: See TracBrowser for help on using the repository browser.