Changeset 4f9636f for src/benchmark/csv-data.c
- Timestamp:
- May 5, 2017, 11:05:53 AM (6 years ago)
- Branches:
- aaron-thesis, arm-eh, 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:
- 982ed5b, c10ee66
- Parents:
- 45a4ea7 (diff), bd951f7 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/benchmark/csv-data.c
r45a4ea7 r4f9636f 1 1 #include <fstream> 2 #include <monitor> 2 3 #include <stdlib> 3 4 #include <thread> 4 5 5 extern "C" { 6 #include <unistd.h> // sysconf 7 #include <sys/times.h> // times 8 #include <time.h> 9 } 10 11 inline unsigned long long int Time() { 12 timespec ts; 13 clock_gettime( 14 #if defined( __linux__ ) 15 CLOCK_THREAD_CPUTIME_ID, 16 #elif defined( __freebsd__ ) 17 CLOCK_PROF, 18 #elif defined( __solaris__ ) 19 CLOCK_HIGHRES, 20 #else 21 #error uC++ : internal error, unsupported architecture 22 #endif 23 &ts ); 24 return 1000000000LL * ts.tv_sec + ts.tv_nsec; 25 } // Time 6 #include "bench.h" 26 7 27 8 coroutine GreatSuspender {}; … … 48 29 #endif 49 30 50 51 31 //----------------------------------------------------------------------------- 32 // coroutine context switch 52 33 long long int measure_coroutine() { 53 34 const unsigned int NoOfTimes = N; … … 67 48 } 68 49 50 //----------------------------------------------------------------------------- 51 // thread context switch 69 52 long long int measure_thread() { 70 53 const unsigned int NoOfTimes = N; … … 80 63 } 81 64 65 //----------------------------------------------------------------------------- 66 // single monitor entry 67 monitor mon_t {}; 68 void dummy( mon_t * mutex m ) {} 69 70 long long int measure_1_monitor_entry() { 71 const unsigned int NoOfTimes = N; 72 long long int StartTime, EndTime; 73 mon_t mon; 74 75 StartTime = Time(); 76 for ( volatile unsigned int i = 0; i < NoOfTimes; i += 1 ) { 77 dummy( &mon ); 78 } 79 EndTime = Time(); 80 81 return ( EndTime - StartTime ) / NoOfTimes; 82 } 83 84 //----------------------------------------------------------------------------- 85 // multi monitor entry 86 void dummy( mon_t * mutex m1, mon_t * mutex m2 ) {} 87 88 long long int measure_2_monitor_entry() { 89 const unsigned int NoOfTimes = N; 90 long long int StartTime, EndTime; 91 mon_t mon1, mon2; 92 93 StartTime = Time(); 94 for ( volatile unsigned int i = 0; i < NoOfTimes; i += 1 ) { 95 dummy( &mon1, &mon2 ); 96 } 97 EndTime = Time(); 98 99 return ( EndTime - StartTime ) / NoOfTimes; 100 } 101 82 102 int main() 83 103 { 84 sout | time(NULL) | ',' | measure_coroutine() | ',' | measure_thread() | endl; 104 sout | time(NULL) | ','; 105 sout | measure_coroutine() | ','; 106 sout | measure_thread() | ','; 107 sout | measure_1_monitor_entry() | ','; 108 sout | measure_2_monitor_entry() | endl; 85 109 }
Note: See TracChangeset
for help on using the changeset viewer.