ADT
        arm-eh
        ast-experimental
        enum
        forall-pointer-decay
        jacob/cs343-translation
        jenkins-sandbox
        new-ast
        new-ast-unique-expr
        pthread-emulation
        qualifiedEnum
      
      
        
          | Last change
 on this file since c93fd72 was             b4107c8, checked in by Peter A. Buhr <pabuhr@…>, 6 years ago | 
        
          | 
update existing benchmarks for changes to bench.h, add new benchmarks in new programming languages
 | 
        
          | 
              
Property                 mode
 set to                 100644 | 
        
          | File size:
            731 bytes | 
      
      
| Line |  | 
|---|
| 1 | package main | 
|---|
| 2 |  | 
|---|
| 3 | import ( | 
|---|
| 4 | "fmt" | 
|---|
| 5 | "time" | 
|---|
| 6 | "flag" | 
|---|
| 7 | "runtime" | 
|---|
| 8 | ) | 
|---|
| 9 |  | 
|---|
| 10 | //======================================= | 
|---|
| 11 | // time context switch | 
|---|
| 12 | //======================================= | 
|---|
| 13 |  | 
|---|
| 14 | var shake chan bool = make( chan bool ) | 
|---|
| 15 |  | 
|---|
| 16 | func ContextSwitch(N int) { | 
|---|
| 17 | start := time.Now() | 
|---|
| 18 | for i := 1; i <= N; i += 1 { | 
|---|
| 19 | runtime.Gosched() | 
|---|
| 20 | } | 
|---|
| 21 | end := time.Now() | 
|---|
| 22 | fmt.Printf("%d\n", end.Sub(start) / time.Duration(N)) | 
|---|
| 23 | shake <- true   // indicate completion | 
|---|
| 24 | } | 
|---|
| 25 |  | 
|---|
| 26 | //======================================= | 
|---|
| 27 | // benchmark driver | 
|---|
| 28 | //======================================= | 
|---|
| 29 |  | 
|---|
| 30 | func main() { | 
|---|
| 31 | times := flag.Int( "times", 10000000, "loop iterations" ) | 
|---|
| 32 | go ContextSwitch( *times )              // context switch | 
|---|
| 33 | <- shake | 
|---|
| 34 | } | 
|---|
| 35 |  | 
|---|
| 36 | // Local Variables: // | 
|---|
| 37 | // tab-width: 4 // | 
|---|
| 38 | // End: // | 
|---|
       
      
  Note:
 See   
TracBrowser
 for help on using the repository browser.