source:
benchmark/mutex/goroutine.go@
d1c47c2
      
      | Last change on this file since d1c47c2 was 50cfa99, checked in by , 6 years ago | |
|---|---|
| 
 | |
| File size: 487 bytes | |
| Rev | Line | |
|---|---|---|
| [b4107c8] | 1 | package main | 
| 2 | ||
| 3 | import ( | |
| [50cfa99] | 4 | "fmt" | 
| 5 | "time" | |
| 6 | "os" | |
| 7 | "strconv" | |
| 8 | "sync" | |
| [b4107c8] | 9 | ) | 
| 10 | ||
| 11 | var mutex sync.Mutex | |
| 12 | ||
| 13 | func call() { | |
| [50cfa99] | 14 | mutex.Lock(); | 
| 15 | mutex.Unlock(); | |
| [b4107c8] | 16 | } | 
| 17 | func main() { | |
| [50cfa99] | 18 | var times int = 10000000 | 
| 19 | if len( os.Args ) > 2 { os.Exit( 1 ) } | |
| 20 | if len( os.Args ) == 2 { times, _ = strconv.Atoi(os.Args[1]) } | |
| 21 | ||
| [b4107c8] | 22 | start := time.Now() | 
| [50cfa99] | 23 | for i := 1; i <= times; i += 1 { | 
| [b4107c8] | 24 | call(); | 
| 25 | } | |
| 26 | end := time.Now() | |
| [50cfa99] | 27 | fmt.Printf( "%d\n", end.Sub(start) / time.Duration(times) ) | 
| [b4107c8] | 28 | } | 
| 29 | ||
| 30 | // Local Variables: // | |
| 31 | // tab-width: 4 // | |
| 32 | // End: // | 
  Note:
 See   TracBrowser
 for help on using the repository browser.
    