source: src/benchmark/bench.c @ 4cedd9f

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

Refactored common code into bench.h

  • Property mode set to 100644
File size: 4.5 KB
RevLine 
[550a338]1
2#include <fstream>
[a91dcc2]3#include <stdlib>
[29f44a74]4#include <thread>
[550a338]5
[8cb6fcd]6#include "bench.h"
[550a338]7
[a91dcc2]8//=======================================
9// time struct
10//=======================================
11
12// prevent dead-code removal
13struct StructDummy {
14        volatile int i;
15};
16
17void ?{}(StructDummy * this) __attribute__(( noinline )) {
18        this->i = 2;
19}
20
21int get_i(StructDummy * this) {
22        return this->i;
23}
24
25forall( dtype T | { int get_i(T*); } )
26int bidirectional( StructDummy * this ) __attribute__(( noinline )) {
27        return get_i( this );
28}
29
30void BlockStructCreateDelete( int N ) {
31    long long int StartTime, EndTime;
32
33    StartTime = Time();
34    for ( int i = 0; i < N; i += 1 ) {
35        StructDummy dummy;
36    }
37    EndTime = Time();
38    sout | "\t " | ( EndTime - StartTime ) / N;
39}
40
41void DynamicStructCreateDelete( int N ) {
42    long long int StartTime, EndTime;
43
44    StartTime = Time();
45    for ( int i = 0; i < N; i += 1 ) {
46        StructDummy *dummy = new();
47        delete(dummy);
48    }
49    EndTime = Time();
50    sout | "\t " | ( EndTime - StartTime ) / N;
51}
52
53void StructBidirectional( int N ) {
54    long long int StartTime, EndTime;
55    StructDummy dummy;
56    volatile int rv __attribute__(( unused ));
57
58    StartTime = Time();
59    for ( int i = 0; i < N; i += 1 ) {
60        rv = bidirectional( &dummy ); 
61    }
62    EndTime = Time();
63    sout | "\t " | ( EndTime - StartTime ) / N;
64}
65
[550a338]66//=======================================
67// time coroutine
68//=======================================
69
[b510ac2]70coroutine CoroutineDummy {};
[a91dcc2]71void main(CoroutineDummy * this) {}
72
73void ?{}(CoroutineDummy * this) {
74        prime(this);
75}
76
77void BlockCoroutineCreateDelete( int N ) {
78    long long int StartTime, EndTime;
79
80    StartTime = Time();
81    for ( int i = 0; i < N; i += 1 ) {
82        CoroutineDummy dummy;
83    }
84    EndTime = Time();
85    sout | "\t " | ( EndTime - StartTime ) / N;
86}
87
88void DynamicCoroutineCreateDelete( int N ) {
89    long long int StartTime, EndTime;
90
91    StartTime = Time();
92    for ( int i = 0; i < N; i += 1 ) {
93        CoroutineDummy * dummy = new();
94        delete(dummy);
95    }
96    EndTime = Time();
97    sout | "\t " | ( EndTime - StartTime ) / N;
98}
99
[b510ac2]100coroutine CoroutineResume {
[550a338]101    int N;
102};
103
104void ?{}(CoroutineResume* this, int N) {
105      this->N = N;
106        prime(this);
107}
108
[a91dcc2]109void main(CoroutineResume* this) {
[550a338]110        for ( int i = 1; i <= this->N; i += 1 ) {
111                suspend();
[a91dcc2]112        }
113}
[550a338]114
115void resumer(CoroutineResume* this) {
116        long long int StartTime, EndTime;
117
118        StartTime = Time();
119        for ( int i = 1; i <= this->N; i += 1 ) {
120                resume(this);
[a91dcc2]121        }
[550a338]122        EndTime = Time();
123        sout | "\t " | ( EndTime - StartTime ) / this->N;
[a91dcc2]124}
125
126//=======================================
127// time task
128//=======================================
129
[b510ac2]130thread ThreadDummy {};
[a91dcc2]131void main(ThreadDummy * this) {}
132
133void BlockTaskCreateDelete( int N ) {
134    long long int StartTime, EndTime;
135
136    StartTime = Time();
137    for ( int i = 0; i < N; i += 1 ) {
138        scoped(ThreadDummy) dummy;
139    }
140    EndTime = Time();
141    sout | "\t " | ( EndTime - StartTime ) / N;
142}
143
144void DynamicTaskCreateDelete( int N ) {
145    long long int StartTime, EndTime;
146
147    StartTime = Time();
148    for ( int i = 0; i < N; i += 1 ) {
149        scoped(ThreadDummy) * dummy = new();
150        delete(dummy);
151    }
152    EndTime = Time();
153    sout | "\t " | ( EndTime - StartTime ) / N;
154}
155
[b510ac2]156thread ContextSwitch {
[a91dcc2]157    int N;
158    long long result;
159};
160
161void main(ContextSwitch * this) {   
162        long long int StartTime, EndTime;
163
164        StartTime = Time();
165        for ( int i = 1; i <= this->N; i += 1 ) {
166            yield();
167        } // for
168        EndTime = Time();
169        this->result = ( EndTime - StartTime ) / this->N;
170}
171
172void ?{}(ContextSwitch * this, int N) {
173        this->N = N;
174}
175
176void ^?{}(ContextSwitch * this) {
177        sout | "\t " | this->result;
178}
179
180//=======================================
181// benchmark driver
182//=======================================
[550a338]183
184
185int main() {
186        const int NoOfTimes =
187#if defined( __U_DEBUG__ )                              // takes longer so run fewer iterations
188        100000;
189#else
190        1000000;
191#endif // __U_DEBUG__
192
[a91dcc2]193        sout | "\t\tcreate\tcreate\tcall/" | endl;
[550a338]194        sout | "(nsecs)";
[a91dcc2]195        sout | "\t\tdelete/\tdelete/\tctx" | endl;
196        sout | "\t\tblock\tdynamic\tcycle" | endl;
[550a338]197
[a91dcc2]198        sout | "object\t";
199        BlockStructCreateDelete( NoOfTimes );
200        DynamicStructCreateDelete( NoOfTimes );
201        StructBidirectional( NoOfTimes );
202        sout | endl;
[550a338]203
204        sout | "coroutine";
[a91dcc2]205        BlockCoroutineCreateDelete( NoOfTimes );
206        DynamicCoroutineCreateDelete( NoOfTimes );
[550a338]207        {
208                CoroutineResume resumer = { NoOfTimes };
209                resumer(&resumer);
210        }
[a91dcc2]211        sout | endl;
[550a338]212
[a91dcc2]213        sout | "task\t";
214        BlockTaskCreateDelete( NoOfTimes );
215        DynamicTaskCreateDelete( NoOfTimes );
216        {
[b510ac2]217                ContextSwitch dummy = { (int)NoOfTimes };               // context switch
[a91dcc2]218        }
[550a338]219        sout | "\t" | endl;
220}
Note: See TracBrowser for help on using the repository browser.