LEFT | RIGHT |
1 // Copyright 2011 The Go Authors. All rights reserved. | 1 // Copyright 2011 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
| 4 |
| 5 // Tests goroutine creation/completion performance/scalability. |
| 6 // Spawns a lot of goroutines concurrently. goroutine-centr test uses single ato
mic |
| 7 // variable to track when all the goroutines are created and executed (this sing
le |
| 8 // var can hinder scalability). goroutine-distr test uses distributed variables |
| 9 // to track completion (it does not create scalability bottleneck, but puts addi
tional |
| 10 // pressure onto GC). |
| 11 // Expected to scale almost linearly. |
4 | 12 |
5 package main | 13 package main |
6 | 14 |
7 import ( | 15 import ( |
8 "container/vector" | 16 "container/vector" |
9 "runtime" | 17 "runtime" |
10 "sync/atomic" | 18 "sync/atomic" |
11 ) | 19 ) |
12 | 20 |
13 const ( | 21 const ( |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 runtime.Gosched() | 64 runtime.Gosched() |
57 } | 65 } |
58 totalWork += COUNT | 66 totalWork += COUNT |
59 } | 67 } |
60 } | 68 } |
61 | 69 |
62 func SuiteGoroutine(benchmarks *vector.Vector) { | 70 func SuiteGoroutine(benchmarks *vector.Vector) { |
63 benchmarks.Push(&Benchmark{"goroutine-distr", benchmarkGorotuineDistribu
ted}) | 71 benchmarks.Push(&Benchmark{"goroutine-distr", benchmarkGorotuineDistribu
ted}) |
64 benchmarks.Push(&Benchmark{"goroutine-centr", benchmarkGorotuineCentrali
zed}) | 72 benchmarks.Push(&Benchmark{"goroutine-centr", benchmarkGorotuineCentrali
zed}) |
65 } | 73 } |
LEFT | RIGHT |