source:
benchmark/creation/goroutine.go@
e21f253
| Last change on this file since e21f253 was 50cfa99, checked in by , 6 years ago | |
|---|---|
|
|
| File size: 660 bytes | |
| Rev | Line | |
|---|---|---|
| [50abab9] | 1 | package main |
| 2 | ||
| 3 | import ( | |
| [50cfa99] | 4 | "fmt" |
| 5 | "time" | |
| 6 | "os" | |
| 7 | "strconv" | |
| [50abab9] | 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() { | |
| [50cfa99] | 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 | ||
| [50abab9] | 25 | start := time.Now() |
| [50cfa99] | 26 | for i := 1; i <= times; i += 1 { |
| [50abab9] | 27 | go noop() // creation |
| [b4107c8] | 28 | <- shake // wait for completion |
| [50abab9] | 29 | } |
| 30 | end := time.Now() | |
| [50cfa99] | 31 | fmt.Printf( "%d\n", end.Sub(start) / time.Duration(times) ) |
| [50abab9] | 32 | } |
| [b4107c8] | 33 | |
| 34 | // Local Variables: // | |
| 35 | // tab-width: 4 // | |
| 36 | // End: // |
Note:
See TracBrowser
for help on using the repository browser.