source: src/benchmark/bench.h @ 8ad6533

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsdeferred_resndemanglerenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumwith_gc
Last change on this file since 8ad6533 was 8ad6533, checked in by Peter A. Buhr <pabuhr@…>, 6 years ago

remove cfatime.h, move itimerval constructor to "time", update concurrent examples to use Duration

  • 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
8        #include <sys/times.h>                                  // times
9        #include <time.h>
[0cf5b79]10#if defined(__cforall)
[8cb6fcd]11}
[8ad6533]12//#include <bits/cfatime.h>
[d67cdb7]13#endif
[8cb6fcd]14
[d8548e2]15
[d67cdb7]16static inline unsigned long long int Time() {
17    struct timespec ts;
[8cb6fcd]18    clock_gettime(
19#if defined( __linux__ )
20         CLOCK_THREAD_CPUTIME_ID,
21#elif defined( __freebsd__ )
22         CLOCK_PROF,
23#elif defined( __solaris__ )
24         CLOCK_HIGHRES,
25#else
26    #error uC++ : internal error, unsupported architecture
27#endif
28         &ts );
29    return 1000000000LL * ts.tv_sec + ts.tv_nsec;
30} // Time
31
[034165a]32#ifndef BENCH_N
33#define BENCH_N 500 //10000000
[7286a40]34#endif
35
[034165a]36#define BENCH(statement, output)                \
[b7170a64]37        size_t n = BENCH_N;                     \
38        if( argc > 2 ) return 1;                \
39        if( argc == 2 ) {                               \
40                n = atoi(argv[1]);              \
41        }                                               \
[034165a]42        long long int StartTime, EndTime;       \
[b7170a64]43        StartTime = Time();                     \
44        statement;                                      \
45        EndTime = Time();                               \
[034165a]46        unsigned long long int output =         \
[b7170a64]47        ( EndTime - StartTime ) / n;
[034165a]48
[d8548e2]49__cfa_time_t default_preemption() {
[7286a40]50        return 0;
[8ad6533]51}
Note: See TracBrowser for help on using the repository browser.