ADT
        aaron-thesis
        arm-eh
        ast-experimental
        cleanup-dtors
        deferred_resn
        demangler
        enum
        forall-pointer-decay
        jacob/cs343-translation
        jenkins-sandbox
        new-ast
        new-ast-unique-expr
        new-env
        no_list
        persistent-indexer
        pthread-emulation
        qualifiedEnum
        resolv-new
        with_gc
      
      
        
          | Last change
 on this file since 031a2c95 was             6db3e73, checked in by Thierry Delisle <tdelisle@…>, 9 years ago | 
        
          | 
Fixed 32-bit benchmark compilation
 | 
        
          | 
              
Property                 mode
 set to                 100644 | 
        
          | File size:
            1.6 KB | 
      
      
| Rev | Line |  | 
|---|
| [cf97ccb] | 1 | #include <fstream> | 
|---|
|  | 2 | #include <stdlib> | 
|---|
|  | 3 | #include <threads> | 
|---|
|  | 4 |  | 
|---|
| [6db3e73] | 5 | extern "C" { | 
|---|
| [cf97ccb] | 6 | #include <unistd.h>                                     // sysconf | 
|---|
|  | 7 | #include <sys/times.h>                                  // times | 
|---|
|  | 8 | #include <time.h> | 
|---|
| [6db3e73] | 9 | } | 
|---|
| [cf97ccb] | 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 c; | 
|---|
|  | 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 | { | 
|---|
| [b3e9729] | 88 | sout | time(NULL) | ',' | measure_coroutine() | ',' | measure_thread() | endl; | 
|---|
| [cf97ccb] | 89 | } | 
|---|
       
      
  Note:
 See   
TracBrowser
 for help on using the repository browser.