source:
benchmark/creation/goroutine.go
@
6e540ea
Last change on this file since 6e540ea was b4107c8, checked in by , 4 years ago | |
---|---|
|
|
File size: 602 bytes |
Rev | Line | |
---|---|---|
[50abab9] | 1 | package main |
2 | ||
3 | import ( | |
4 | "fmt" | |
5 | "time" | |
[b4107c8] | 6 | "flag" |
[50abab9] | 7 | ) |
8 | ||
9 | var shake chan bool = make( chan bool ) | |
10 | ||
11 | func noop() { | |
12 | shake <- true // indicate completion | |
13 | } | |
14 | ||
15 | //======================================= | |
16 | // benchmark driver | |
17 | //======================================= | |
18 | ||
19 | func main() { | |
[b4107c8] | 20 | times := flag.Int( "times", 500000, "loop iterations" ) |
21 | flag.Parse() | |
[50abab9] | 22 | start := time.Now() |
[b4107c8] | 23 | for i := 1; i <= *times; i += 1 { |
[50abab9] | 24 | go noop() // creation |
[b4107c8] | 25 | <- shake // wait for completion |
[50abab9] | 26 | } |
27 | end := time.Now() | |
[b4107c8] | 28 | fmt.Printf( "%d\n", end.Sub(start) / time.Duration(*times) ) |
[50abab9] | 29 | } |
[b4107c8] | 30 | |
31 | // Local Variables: // | |
32 | // tab-width: 4 // | |
33 | // End: // |
Note: See TracBrowser
for help on using the repository browser.