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

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 f54a0ab was bd37119, checked in by Rob Schluntz <rschlunt@…>, 7 years ago

Fix benchmarks for references

  • Property mode set to 100644
File size: 4.1 KB
RevLine 
[cf97ccb]1#include <fstream>
[bd951f7]2#include <monitor>
[cf97ccb]3#include <stdlib>
[29f44a74]4#include <thread>
[cf97ccb]5
[8cb6fcd]6#include "bench.h"
[cf97ccb]7
[b510ac2]8coroutine GreatSuspender {};
[cf97ccb]9
[bd37119]10void ?{}( GreatSuspender & this ) {
[cf97ccb]11        prime(this);
12}
13
[bd37119]14void main( GreatSuspender & this )
[cf97ccb]15{
16        while( true ) {
17                suspend();
18        }
19}
20
21void resumer( GreatSuspender * this, const unsigned int NoOfTimes ) {
22        for ( volatile unsigned int i = 0; i < NoOfTimes; i += 1 ) {
[bd37119]23                resume( *this );
[cf97ccb]24        }
25}
26
[bd951f7]27//-----------------------------------------------------------------------------
28// coroutine context switch
[cf97ccb]29long long int measure_coroutine() {
30        const unsigned int NoOfTimes = N;
31        long long int StartTime, EndTime;
32
33        GreatSuspender s;
34
35        StartTime = Time();
36        resumer( &s, NoOfTimes );
37        EndTime = Time();
38
39        return ( EndTime - StartTime ) / NoOfTimes;
40}
41
[bd951f7]42//-----------------------------------------------------------------------------
43// thread context switch
[cf97ccb]44long long int measure_thread() {
45        const unsigned int NoOfTimes = N;
46        long long int StartTime, EndTime;
47
48        StartTime = Time();
49        for ( volatile unsigned int i = 0; i < NoOfTimes; i += 1 ) {
50                yield();
51        }
52        EndTime = Time();
53
54        return ( EndTime - StartTime ) / NoOfTimes;
55}
56
[bd951f7]57//-----------------------------------------------------------------------------
58// single monitor entry
59monitor mon_t {};
[bd37119]60void dummy( mon_t & mutex m ) {}
[bd951f7]61
62long long int measure_1_monitor_entry() {
63        const unsigned int NoOfTimes = N;
64        long long int StartTime, EndTime;
65        mon_t mon;
66
67        StartTime = Time();
68        for ( volatile unsigned int i = 0; i < NoOfTimes; i += 1 ) {
[bd37119]69                dummy( mon );
[bd951f7]70        }
71        EndTime = Time();
72
73        return ( EndTime - StartTime ) / NoOfTimes;
74}
75
76//-----------------------------------------------------------------------------
77// multi monitor entry
[bd37119]78void dummy( mon_t & mutex m1,  mon_t & mutex m2 ) {}
[bd951f7]79
80long long int measure_2_monitor_entry() {
81        const unsigned int NoOfTimes = N;
82        long long int StartTime, EndTime;
83        mon_t mon1, mon2;
84
85        StartTime = Time();
86        for ( volatile unsigned int i = 0; i < NoOfTimes; i += 1 ) {
[bd37119]87                dummy( mon1, mon2 );
[bd951f7]88        }
89        EndTime = Time();
90
91        return ( EndTime - StartTime ) / NoOfTimes;
92}
93
[43426d4]94//-----------------------------------------------------------------------------
95// single internal sched entry
96mon_t mon1;
97
[7286a40]98condition cond1a;
[43426d4]99condition cond1b;
100
101thread thrd1a { long long int * out; };
102thread thrd1b {};
103
[bd37119]104void ?{}( thrd1a & this, long long int * out ) {
105        this.out = out;
[43426d4]106}
107
[bd37119]108void side1A( mon_t & mutex a, long long int * out ) {
[43426d4]109        long long int StartTime, EndTime;
110
111        StartTime = Time();
112        for( int i = 0;; i++ ) {
113                signal(&cond1a);
114                if( i > N ) break;
115                wait(&cond1b);
116        }
117        EndTime = Time();
118
119        *out = ( EndTime - StartTime ) / N;
120}
121
[bd37119]122void side1B( mon_t & mutex a ) {
[43426d4]123        for( int i = 0;; i++ ) {
124                signal(&cond1b);
125                if( i > N ) break;
126                wait(&cond1a);
127        }
128}
129
[bd37119]130void main( thrd1a & this ) { side1A( mon1, this.out ); }
131void main( thrd1b & this ) { side1B( mon1 ); }
[43426d4]132
133long long int measure_1_sched_int() {
134        long long int t;
135        {
136                thrd1a a = { &t };
137                thrd1b b;
138        }
139        return t;
140}
141
142//-----------------------------------------------------------------------------
143// multi internal sched entry
144mon_t mon2;
145
[7286a40]146condition cond2a;
[43426d4]147condition cond2b;
148
149thread thrd2a { long long int * out; };
150thread thrd2b {};
151
[bd37119]152void ?{}( thrd2a & this, long long int * out ) {
153        this.out = out;
[43426d4]154}
155
[bd37119]156void side2A( mon_t & mutex a, mon_t & mutex b, long long int * out ) {
[43426d4]157        long long int StartTime, EndTime;
158
159        StartTime = Time();
160        for( int i = 0;; i++ ) {
161                signal(&cond2a);
162                if( i > N ) break;
163                wait(&cond2b);
164        }
165        EndTime = Time();
166
167        *out = ( EndTime - StartTime ) / N;
168}
169
[bd37119]170void side2B( mon_t & mutex a, mon_t & mutex b ) {
[43426d4]171        for( int i = 0;; i++ ) {
172                signal(&cond2b);
173                if( i > N ) break;
174                wait(&cond2a);
175        }
176}
177
[bd37119]178void main( thrd2a & this ) { side2A( mon1, mon2, this.out ); }
179void main( thrd2b & this ) { side2B( mon1, mon2 ); }
[43426d4]180
181long long int measure_2_sched_int() {
182        long long int t;
183        {
184                thrd2a a = { &t };
185                thrd2b b;
186        }
187        return t;
188}
189
190//-----------------------------------------------------------------------------
191// main loop
[cf97ccb]192int main()
193{
[bd951f7]194        sout | time(NULL) | ',';
195        sout | measure_coroutine() | ',';
196        sout | measure_thread() | ',';
197        sout | measure_1_monitor_entry() | ',';
[43426d4]198        sout | measure_2_monitor_entry() | ',';
199        sout | measure_1_sched_int() | ',';
200        sout | measure_2_sched_int() | endl;
[cf97ccb]201}
Note: See TracBrowser for help on using the repository browser.