source: src/benchmark/bench.h @ 5248789

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 5248789 was 399a908, checked in by Thierry Delisle <tdelisle@…>, 7 years ago

Fixed benchmarks

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