source: src/benchmark/CorCtxSwitch.c @ f51ef6f

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

Added new benchmark folder and added more focused benchmarks for thread/coroutine context switch

  • Property mode set to 100644
File size: 1.2 KB
RevLine 
[de90452]1#include <fstream>
2#include <stdlib>
3#include <threads>
4
5#include <unistd.h>                                     // sysconf
6#include <sys/times.h>                                  // times
7#include <time.h>
8
9inline unsigned long long int Time() {
10    timespec ts;
11    clock_gettime(
12#if defined( __linux__ )
13         CLOCK_THREAD_CPUTIME_ID,
14#elif defined( __freebsd__ )
15         CLOCK_PROF,
16#elif defined( __solaris__ )
17         CLOCK_HIGHRES,
18#else
19    #error uC++ : internal error, unsupported architecture
20#endif
21         &ts );
22    return 1000000000LL * ts.tv_sec + ts.tv_nsec;
23} // Time
24
25struct GreatSuspender {
26        coroutine c;
27};
28
29DECL_COROUTINE(GreatSuspender);
30
31void ?{}( GreatSuspender * this ) {
32        prime(this);
33}
34
35void main( GreatSuspender * this )
36{
37        while( true ) {
38                suspend();
39        }
40}
41
42void resumer( GreatSuspender * this, const unsigned int NoOfTimes ) {
43        for ( volatile unsigned int i = 0; i < NoOfTimes; i += 1 ) {
44                resume( this );
45        }
46}
47
48#ifndef N
49#define N 100000000
50#endif
51
52int main() {
53        const unsigned int NoOfTimes = N;
54        long long int StartTime, EndTime;
55
56        GreatSuspender s;
57
58        StartTime = Time();
59        // for ( volatile unsigned int i = 0; i < NoOfTimes; i += 1 ) {
60        //      resume( this_coroutine() );
61        //      // resume( &s );       
62        // }
63        resumer( &s, NoOfTimes );
64        EndTime = Time();
65
66        sout | ( EndTime - StartTime ) / NoOfTimes | endl;
67}
Note: See TracBrowser for help on using the repository browser.