source: src/benchmark/bench.h@ e6c5e79

ADT aaron-thesis arm-eh ast-experimental cleanup-dtors deferred_resn demangler enum forall-pointer-decay jacob/cs343-translation jenkins-sandbox new-ast new-ast-unique-expr new-env no_list persistent-indexer pthread-emulation qualifiedEnum resolv-new with_gc
Last change on this file since e6c5e79 was d8548e2, checked in by Thierry Delisle <tdelisle@…>, 8 years ago

Fixed preemption and changed default_preemption to use cfa_time_t

  • Property mode set to 100644
File size: 1.0 KB
Line 
1#pragma once
2
3#if defined(__cforall)
4extern "C" {
5#endif
6 #include <stdlib.h>
7 #include <unistd.h> // sysconf
8 #include <sys/times.h> // times
9 #include <time.h>
10#if defined(__cforall)
11}
12#include <bits/cfatime.h>
13#endif
14
15
16static inline unsigned long long int Time() {
17 struct timespec ts;
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
32#ifndef BENCH_N
33#define BENCH_N 500 //10000000
34#endif
35
36#define BENCH(statement, output) \
37 size_t n = BENCH_N; \
38 if( argc > 2 ) return 1; \
39 if( argc == 2 ) { \
40 n = atoi(argv[1]); \
41 } \
42 long long int StartTime, EndTime; \
43 StartTime = Time(); \
44 statement; \
45 EndTime = Time(); \
46 unsigned long long int output = \
47 ( EndTime - StartTime ) / n;
48
49__cfa_time_t default_preemption() {
50 return 0;
51}
Note: See TracBrowser for help on using the repository browser.