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 03bb816 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.6 KB
|
Line | |
---|
1 | #include <fstream> |
---|
2 | #include <stdlib> |
---|
3 | #include <thread> |
---|
4 | |
---|
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 |
---|
26 | |
---|
27 | struct GreatSuspender { |
---|
28 | coroutine_desc __cor; |
---|
29 | }; |
---|
30 | |
---|
31 | DECL_COROUTINE(GreatSuspender); |
---|
32 | |
---|
33 | void ?{}( GreatSuspender * this ) { |
---|
34 | prime(this); |
---|
35 | } |
---|
36 | |
---|
37 | void main( GreatSuspender * this ) |
---|
38 | { |
---|
39 | while( true ) { |
---|
40 | suspend(); |
---|
41 | } |
---|
42 | } |
---|
43 | |
---|
44 | void resumer( GreatSuspender * this, const unsigned int NoOfTimes ) { |
---|
45 | for ( volatile unsigned int i = 0; i < NoOfTimes; i += 1 ) { |
---|
46 | resume( this ); |
---|
47 | } |
---|
48 | } |
---|
49 | |
---|
50 | #ifndef N |
---|
51 | #define N 100000000 |
---|
52 | #endif |
---|
53 | |
---|
54 | |
---|
55 | |
---|
56 | long long int measure_coroutine() { |
---|
57 | const unsigned int NoOfTimes = N; |
---|
58 | long long int StartTime, EndTime; |
---|
59 | |
---|
60 | GreatSuspender s; |
---|
61 | |
---|
62 | StartTime = Time(); |
---|
63 | // for ( volatile unsigned int i = 0; i < NoOfTimes; i += 1 ) { |
---|
64 | // resume( this_coroutine() ); |
---|
65 | // // resume( &s ); |
---|
66 | // } |
---|
67 | resumer( &s, NoOfTimes ); |
---|
68 | EndTime = Time(); |
---|
69 | |
---|
70 | return ( EndTime - StartTime ) / NoOfTimes; |
---|
71 | } |
---|
72 | |
---|
73 | long long int measure_thread() { |
---|
74 | const unsigned int NoOfTimes = N; |
---|
75 | long long int StartTime, EndTime; |
---|
76 | |
---|
77 | StartTime = Time(); |
---|
78 | for ( volatile unsigned int i = 0; i < NoOfTimes; i += 1 ) { |
---|
79 | yield(); |
---|
80 | } |
---|
81 | EndTime = Time(); |
---|
82 | |
---|
83 | return ( EndTime - StartTime ) / NoOfTimes; |
---|
84 | } |
---|
85 | |
---|
86 | int main() |
---|
87 | { |
---|
88 | sout | time(NULL) | ',' | measure_coroutine() | ',' | measure_thread() | endl; |
---|
89 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.