source: src/benchmark/csv-data.c @ cf97ccb

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsdeferred_resndemanglerenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newwith_gc
Last change on this file since cf97ccb was cf97ccb, checked in by Thierry Delisle <tdelisle@…>, 8 years ago

Added benchmark that generates 1 line of csv

  • Property mode set to 100644
File size: 1.6 KB
Line 
1#include <fstream>
2#include <stdlib>
3#include <threads>
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
25struct GreatSuspender {
26        coroutine c;
27};
28
29DECL_COROUTINE(GreatSuspender);
30
31void ?{}( GreatSuspender * this ) {
32        prime(this);
33}
34
35void main( GreatSuspender * this )
36{
37        while( true ) {
38                suspend();
39        }
40}
41
42void resumer( GreatSuspender * this, const unsigned int NoOfTimes ) {
43        for ( volatile unsigned int i = 0; i < NoOfTimes; i += 1 ) {
44                resume( this );
45        }
46}
47
48#ifndef N
49#define N 100000000
50#endif
51
52
53
54long long int measure_coroutine() {
55        const unsigned int NoOfTimes = N;
56        long long int StartTime, EndTime;
57
58        GreatSuspender s;
59
60        StartTime = Time();
61        // for ( volatile unsigned int i = 0; i < NoOfTimes; i += 1 ) {
62        //      resume( this_coroutine() );
63        //      // resume( &s );
64        // }
65        resumer( &s, NoOfTimes );
66        EndTime = Time();
67
68        return ( EndTime - StartTime ) / NoOfTimes;
69}
70
71long long int measure_thread() {
72        const unsigned int NoOfTimes = N;
73        long long int StartTime, EndTime;
74
75        StartTime = Time();
76        for ( volatile unsigned int i = 0; i < NoOfTimes; i += 1 ) {
77                yield();
78        }
79        EndTime = Time();
80
81        return ( EndTime - StartTime ) / NoOfTimes;
82}
83
84int main()
85{
86        sout | time(NULL) | "," | measure_coroutine() | "," | measure_thread() | endl;
87}
Note: See TracBrowser for help on using the repository browser.