source: src/benchmark/csv-data.c@ 8a48f4b

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

Fix benchmarks for references

  • Property mode set to 100644
File size: 4.1 KB
Line 
1#include <fstream>
2#include <monitor>
3#include <stdlib>
4#include <thread>
5
6#include "bench.h"
7
8coroutine GreatSuspender {};
9
10void ?{}( GreatSuspender & this ) {
11 prime(this);
12}
13
14void main( GreatSuspender & this )
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 ) {
23 resume( *this );
24 }
25}
26
27//-----------------------------------------------------------------------------
28// coroutine context switch
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
42//-----------------------------------------------------------------------------
43// thread context switch
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
57//-----------------------------------------------------------------------------
58// single monitor entry
59monitor mon_t {};
60void dummy( mon_t & mutex m ) {}
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 ) {
69 dummy( mon );
70 }
71 EndTime = Time();
72
73 return ( EndTime - StartTime ) / NoOfTimes;
74}
75
76//-----------------------------------------------------------------------------
77// multi monitor entry
78void dummy( mon_t & mutex m1, mon_t & mutex m2 ) {}
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 ) {
87 dummy( mon1, mon2 );
88 }
89 EndTime = Time();
90
91 return ( EndTime - StartTime ) / NoOfTimes;
92}
93
94//-----------------------------------------------------------------------------
95// single internal sched entry
96mon_t mon1;
97
98condition cond1a;
99condition cond1b;
100
101thread thrd1a { long long int * out; };
102thread thrd1b {};
103
104void ?{}( thrd1a & this, long long int * out ) {
105 this.out = out;
106}
107
108void side1A( mon_t & mutex a, long long int * out ) {
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
122void side1B( mon_t & mutex a ) {
123 for( int i = 0;; i++ ) {
124 signal(&cond1b);
125 if( i > N ) break;
126 wait(&cond1a);
127 }
128}
129
130void main( thrd1a & this ) { side1A( mon1, this.out ); }
131void main( thrd1b & this ) { side1B( mon1 ); }
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
146condition cond2a;
147condition cond2b;
148
149thread thrd2a { long long int * out; };
150thread thrd2b {};
151
152void ?{}( thrd2a & this, long long int * out ) {
153 this.out = out;
154}
155
156void side2A( mon_t & mutex a, mon_t & mutex b, long long int * out ) {
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
170void side2B( mon_t & mutex a, mon_t & mutex b ) {
171 for( int i = 0;; i++ ) {
172 signal(&cond2b);
173 if( i > N ) break;
174 wait(&cond2a);
175 }
176}
177
178void main( thrd2a & this ) { side2A( mon1, mon2, this.out ); }
179void main( thrd2b & this ) { side2B( mon1, mon2 ); }
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
192int main()
193{
194 sout | time(NULL) | ',';
195 sout | measure_coroutine() | ',';
196 sout | measure_thread() | ',';
197 sout | measure_1_monitor_entry() | ',';
198 sout | measure_2_monitor_entry() | ',';
199 sout | measure_1_sched_int() | ',';
200 sout | measure_2_sched_int() | endl;
201}
Note: See TracBrowser for help on using the repository browser.