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 sync.Once fast-path scalability under contention. |
| 6 // A set of goroutines repeatedly execute sync.Once.Do() on a single object. |
| 7 // Expected to scale almost linearly. |
4 | 8 |
5 package main | 9 package main |
6 | 10 |
7 import ( | 11 import ( |
8 "container/vector" | 12 "container/vector" |
9 "runtime" | 13 "runtime" |
10 "sync" | 14 "sync" |
11 ) | 15 ) |
12 | 16 |
13 func benchmarkOnce() { | 17 func benchmarkOnce() { |
(...skipping 15 matching lines...) Expand all Loading... |
29 }() | 33 }() |
30 } | 34 } |
31 for p := 0; p != procs; p += 1 { | 35 for p := 0; p != procs; p += 1 { |
32 totalWork += <-compl | 36 totalWork += <-compl |
33 } | 37 } |
34 } | 38 } |
35 | 39 |
36 func SuiteOnce(benchmarks *vector.Vector) { | 40 func SuiteOnce(benchmarks *vector.Vector) { |
37 benchmarks.Push(&Benchmark{"once", benchmarkOnce}) | 41 benchmarks.Push(&Benchmark{"once", benchmarkOnce}) |
38 } | 42 } |
LEFT | RIGHT |