source: src/benchmark/Monitor.c @ 29137d3

aaron-thesisarm-ehcleanup-dtorsdeferred_resndemanglerjacob/cs343-translationjenkins-sandboxnew-astnew-envno_listpersistent-indexerresolv-newwith_gc
Last change on this file since 29137d3 was 29137d3, checked in by Thierry Delisle <tdelisle@…>, 4 years ago

Added benchmakr for test entering and leaving

  • Property mode set to 100644
File size: 827 bytes
Line 
1#include <fstream>
2#include <stdlib>
3#include <thread>
4
5#include <unistd.h>                                     // sysconf
6#include <sys/times.h>                                  // times
7#include <time.h>
8
9inline unsigned long long int Time() {
10    timespec ts;
11    clock_gettime(
12#if defined( __linux__ )
13         CLOCK_THREAD_CPUTIME_ID,
14#elif defined( __freebsd__ )
15         CLOCK_PROF,
16#elif defined( __solaris__ )
17         CLOCK_HIGHRES,
18#else
19    #error uC++ : internal error, unsupported architecture
20#endif
21         &ts );
22    return 1000000000LL * ts.tv_sec + ts.tv_nsec;
23} // Time
24
25#ifndef N
26#define N 10000000
27#endif
28
29monitor mon_t {};
30
31mon_t mon1, mon2;
32
33void dummy( mon_t * mutex a, mon_t * mutex b ) {}
34
35
36
37int main() {
38        long long int StartTime, EndTime;
39
40        StartTime = Time();
41        for( int i = 0; i < N; i++ ) {
42                dummy( &mon1, &mon2 );
43        }
44        EndTime = Time();
45
46        sout | ( EndTime - StartTime ) / N | endl;
47}
Note: See TracBrowser for help on using the repository browser.