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 d0ffed1 was             de90452, checked in by Thierry Delisle <tdelisle@…>, 9 years ago | 
        
          | 
Added new benchmark folder and added more focused benchmarks for thread/coroutine context switch
 | 
        
          | 
              
Property                 mode
 set to                 100644 | 
        
          | File size:
            798 bytes | 
      
      
| Line |  | 
|---|
| 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 |  | 
|---|
| 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 | #ifndef N | 
|---|
| 26 | #define N 100000000 | 
|---|
| 27 | #endif | 
|---|
| 28 |  | 
|---|
| 29 | int main() { | 
|---|
| 30 | const unsigned int NoOfTimes = N; | 
|---|
| 31 | long long int StartTime, EndTime; | 
|---|
| 32 |  | 
|---|
| 33 | StartTime = Time(); | 
|---|
| 34 | for ( volatile unsigned int i = 0; i < NoOfTimes; i += 1 ) { | 
|---|
| 35 | yield(); | 
|---|
| 36 | } | 
|---|
| 37 | EndTime = Time(); | 
|---|
| 38 |  | 
|---|
| 39 | sout | ( EndTime - StartTime ) / NoOfTimes | endl; | 
|---|
| 40 | } | 
|---|
       
      
  Note:
 See   
TracBrowser
 for help on using the repository browser.