ADT
        ast-experimental
        enum
        pthread-emulation
        qualifiedEnum
      
      
        
          | Last change
 on this file since 1e6ffb44 was             50cfa99, checked in by Peter A. Buhr <pabuhr@…>, 6 years ago | 
        
          | 
change Go command-line code to behave like C
 | 
        
          | 
              
Property                 mode
 set to                 100644 | 
        
          | File size:
            660 bytes | 
      
      
| Line |  | 
|---|
| 1 | package main | 
|---|
| 2 |  | 
|---|
| 3 | import ( | 
|---|
| 4 | "fmt" | 
|---|
| 5 | "time" | 
|---|
| 6 | "os" | 
|---|
| 7 | "strconv" | 
|---|
| 8 | ) | 
|---|
| 9 |  | 
|---|
| 10 | var shake chan bool = make( chan bool ) | 
|---|
| 11 |  | 
|---|
| 12 | func noop() { | 
|---|
| 13 | shake <- true   // indicate completion | 
|---|
| 14 | } | 
|---|
| 15 |  | 
|---|
| 16 | //======================================= | 
|---|
| 17 | // benchmark driver | 
|---|
| 18 | //======================================= | 
|---|
| 19 |  | 
|---|
| 20 | func main() { | 
|---|
| 21 | var times int = 10000000 | 
|---|
| 22 | if len( os.Args ) > 2 { os.Exit( 1 ) } | 
|---|
| 23 | if len( os.Args ) == 2 { times, _ = strconv.Atoi(os.Args[1]) } | 
|---|
| 24 |  | 
|---|
| 25 | start := time.Now() | 
|---|
| 26 | for i := 1; i <= times; i += 1 { | 
|---|
| 27 | go noop()               // creation | 
|---|
| 28 | <- shake                // wait for completion | 
|---|
| 29 | } | 
|---|
| 30 | end := time.Now() | 
|---|
| 31 | fmt.Printf( "%d\n", end.Sub(start) / time.Duration(times) ) | 
|---|
| 32 | } | 
|---|
| 33 |  | 
|---|
| 34 | // Local Variables: // | 
|---|
| 35 | // tab-width: 4 // | 
|---|
| 36 | // End: // | 
|---|
       
      
  Note:
 See   
TracBrowser
 for help on using the repository browser.