source: src/benchmark/CorCtxSwitch.c @ 42356f4

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 42356f4 was b510ac2, checked in by Thierry Delisle <tdelisle@…>, 7 years ago

Updated the benchmarks to new concurrency syntax

  • Property mode set to 100644
File size: 1.2 KB
Line 
1#include <fstream>
2#include <stdlib>
3#include <thread>
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
25coroutine GreatSuspender {};
26
27void ?{}( GreatSuspender * this ) {
28        prime(this);
29}
30
31void main( GreatSuspender * this )
32{
33        while( true ) {
34                suspend();
35        }
36}
37
38void resumer( GreatSuspender * this, const unsigned int NoOfTimes ) {
39        for ( volatile unsigned int i = 0; i < NoOfTimes; i += 1 ) {
40                resume( this );
41        }
42}
43
44#ifndef N
45#define N 100000000
46#endif
47
48int main() {
49        const unsigned int NoOfTimes = N;
50        long long int StartTime, EndTime;
51
52        GreatSuspender s;
53
54        StartTime = Time();
55        // for ( volatile unsigned int i = 0; i < NoOfTimes; i += 1 ) {
56        //      resume( this_coroutine() );
57        //      // resume( &s );       
58        // }
59        resumer( &s, NoOfTimes );
60        EndTime = Time();
61
62        sout | ( EndTime - StartTime ) / NoOfTimes | endl;
63}
Note: See TracBrowser for help on using the repository browser.