Changeset a91dcc2 for src/examples/Bench.c
- Timestamp:
- Jan 30, 2017, 12:57:57 PM (8 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
- Children:
- 6dc78dee, a9fc180
- Parents:
- 059531a6
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/examples/Bench.c
r059531a6 ra91dcc2 1 2 1 3 2 #include <fstream> 3 #include <stdlib> 4 4 #include <threads> 5 5 … … 25 25 26 26 //======================================= 27 // time struct 28 //======================================= 29 30 // prevent dead-code removal 31 struct StructDummy { 32 volatile int i; 33 }; 34 35 void ?{}(StructDummy * this) __attribute__(( noinline )) { 36 this->i = 2; 37 } 38 39 int get_i(StructDummy * this) { 40 return this->i; 41 } 42 43 forall( dtype T | { int get_i(T*); } ) 44 int bidirectional( StructDummy * this ) __attribute__(( noinline )) { 45 return get_i( this ); 46 } 47 48 void BlockStructCreateDelete( int N ) { 49 long long int StartTime, EndTime; 50 51 StartTime = Time(); 52 for ( int i = 0; i < N; i += 1 ) { 53 StructDummy dummy; 54 } 55 EndTime = Time(); 56 sout | "\t " | ( EndTime - StartTime ) / N; 57 } 58 59 void DynamicStructCreateDelete( int N ) { 60 long long int StartTime, EndTime; 61 62 StartTime = Time(); 63 for ( int i = 0; i < N; i += 1 ) { 64 StructDummy *dummy = new(); 65 delete(dummy); 66 } 67 EndTime = Time(); 68 sout | "\t " | ( EndTime - StartTime ) / N; 69 } 70 71 void StructBidirectional( int N ) { 72 long long int StartTime, EndTime; 73 StructDummy dummy; 74 volatile int rv __attribute__(( unused )); 75 76 StartTime = Time(); 77 for ( int i = 0; i < N; i += 1 ) { 78 rv = bidirectional( &dummy ); 79 } 80 EndTime = Time(); 81 sout | "\t " | ( EndTime - StartTime ) / N; 82 } 83 84 //======================================= 27 85 // time coroutine 28 86 //======================================= 87 88 struct CoroutineDummy { coroutine c; }; 89 DECL_COROUTINE(CoroutineDummy) 90 void main(CoroutineDummy * this) {} 91 92 void ?{}(CoroutineDummy * this) { 93 prime(this); 94 } 95 96 void BlockCoroutineCreateDelete( int N ) { 97 long long int StartTime, EndTime; 98 99 StartTime = Time(); 100 for ( int i = 0; i < N; i += 1 ) { 101 CoroutineDummy dummy; 102 } 103 EndTime = Time(); 104 sout | "\t " | ( EndTime - StartTime ) / N; 105 } 106 107 void DynamicCoroutineCreateDelete( int N ) { 108 long long int StartTime, EndTime; 109 110 StartTime = Time(); 111 for ( int i = 0; i < N; i += 1 ) { 112 CoroutineDummy * dummy = new(); 113 delete(dummy); 114 } 115 EndTime = Time(); 116 sout | "\t " | ( EndTime - StartTime ) / N; 117 } 29 118 30 119 struct CoroutineResume { … … 33 122 }; 34 123 35 coroutine* get_coroutine(CoroutineResume* this); 36 void co_main(CoroutineResume* this); 124 DECL_COROUTINE(CoroutineResume) 37 125 38 126 void ?{}(CoroutineResume* this, int N) { … … 41 129 } 42 130 43 coroutine* get_coroutine(CoroutineResume* this) { 44 return &this->c; 45 } 46 47 void co_main(CoroutineResume* this) { 131 void main(CoroutineResume* this) { 48 132 for ( int i = 1; i <= this->N; i += 1 ) { 49 133 suspend(); 50 } // for51 } // CoroutineResume::main134 } 135 } 52 136 53 137 void resumer(CoroutineResume* this) { … … 57 141 for ( int i = 1; i <= this->N; i += 1 ) { 58 142 resume(this); 143 } 144 EndTime = Time(); 145 sout | "\t " | ( EndTime - StartTime ) / this->N; 146 } 147 148 //======================================= 149 // time task 150 //======================================= 151 152 struct ThreadDummy { thread t; }; 153 DECL_THREAD(ThreadDummy) 154 void main(ThreadDummy * this) {} 155 156 void BlockTaskCreateDelete( int N ) { 157 long long int StartTime, EndTime; 158 159 StartTime = Time(); 160 for ( int i = 0; i < N; i += 1 ) { 161 scoped(ThreadDummy) dummy; 162 } 163 EndTime = Time(); 164 sout | "\t " | ( EndTime - StartTime ) / N; 165 } 166 167 void DynamicTaskCreateDelete( int N ) { 168 long long int StartTime, EndTime; 169 170 StartTime = Time(); 171 for ( int i = 0; i < N; i += 1 ) { 172 scoped(ThreadDummy) * dummy = new(); 173 delete(dummy); 174 } 175 EndTime = Time(); 176 sout | "\t " | ( EndTime - StartTime ) / N; 177 } 178 179 struct ContextSwitch { 180 int N; 181 long long result; 182 thread t; 183 }; 184 185 DECL_THREAD(ContextSwitch) 186 187 void main(ContextSwitch * this) { 188 long long int StartTime, EndTime; 189 190 StartTime = Time(); 191 for ( int i = 1; i <= this->N; i += 1 ) { 192 yield(); 59 193 } // for 60 194 EndTime = Time(); 61 sout | "\t " | ( EndTime - StartTime ) / this->N; 62 } // CoroutineResume::resumer 195 this->result = ( EndTime - StartTime ) / this->N; 196 } 197 198 void ?{}(ContextSwitch * this, int N) { 199 this->N = N; 200 } 201 202 void ^?{}(ContextSwitch * this) { 203 sout | "\t " | this->result; 204 } 205 206 //======================================= 207 // benchmark driver 208 //======================================= 63 209 64 210 … … 71 217 #endif // __U_DEBUG__ 72 218 73 sout | "\t\tcreate\tcreate\t 16i/4o\t16i/4o\tresume/\tsignal/" | endl;219 sout | "\t\tcreate\tcreate\tcall/" | endl; 74 220 sout | "(nsecs)"; 75 sout | "\t\tdelete/\tdelete/\tbytes\tbytes\tsuspend\twait" | endl; 76 sout | "\t\tblock\tdynamic\tdirect\taccept\tcycle\tcycle" | endl; 77 78 sout | "class\t"; 79 sout | "\t N/A\t N/A\t N/A"; 80 sout | "\t N/A\t N/A\t N/A"; 81 sout | "\t" | endl; 221 sout | "\t\tdelete/\tdelete/\tctx" | endl; 222 sout | "\t\tblock\tdynamic\tcycle" | endl; 223 224 sout | "object\t"; 225 BlockStructCreateDelete( NoOfTimes ); 226 DynamicStructCreateDelete( NoOfTimes ); 227 StructBidirectional( NoOfTimes ); 228 sout | endl; 82 229 83 230 sout | "coroutine"; 84 sout | "\t N/A\t N/A\t N/A";85 sout | "\t N/A";231 BlockCoroutineCreateDelete( NoOfTimes ); 232 DynamicCoroutineCreateDelete( NoOfTimes ); 86 233 { 87 234 CoroutineResume resumer = { NoOfTimes }; 88 235 resumer(&resumer); 89 236 } 90 sout | "\t N/A"; 91 237 sout | endl; 238 239 sout | "task\t"; 240 BlockTaskCreateDelete( NoOfTimes ); 241 DynamicTaskCreateDelete( NoOfTimes ); 242 { 243 scoped(ContextSwitch) dummy = { (int)NoOfTimes }; // context switch 244 } 92 245 sout | "\t" | endl; 93 246 }
Note: See TracChangeset
for help on using the changeset viewer.