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 86c8fd6 was
17af7d1,
checked in by Thierry Delisle <tdelisle@…>, 8 years ago
|
Some clean-up of runtime code
|
-
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 | |
---|
9 | inline 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 | |
---|
25 | struct GreatSuspender { |
---|
26 | coroutine_desc __cor; |
---|
27 | }; |
---|
28 | |
---|
29 | DECL_COROUTINE(GreatSuspender); |
---|
30 | |
---|
31 | void ?{}( GreatSuspender * this ) { |
---|
32 | prime(this); |
---|
33 | } |
---|
34 | |
---|
35 | void main( GreatSuspender * this ) |
---|
36 | { |
---|
37 | while( true ) { |
---|
38 | suspend(); |
---|
39 | } |
---|
40 | } |
---|
41 | |
---|
42 | void 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 | |
---|
52 | int 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.