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

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 bdeba0b was 7d9c987, checked in by Thierry Delisle <tdelisle@…>, 8 years ago

Removed unnecessary comment in benchmarks

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