Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(285)

Side by Side Diff: test/scale/once.go

Issue 4644051: code review 4644051: test: A set of scalability benchmarks. (Closed)
Patch Set: diff -r 6f1145ee588d https://go.googlecode.com/hg/ Created 12 years, 9 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « test/scale/mutex.go ('k') | test/scale/pingpong.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2011 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
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.
8
9 package main
10
11 import (
12 "container/vector"
13 "runtime"
14 "sync"
15 )
16
17 func benchmarkOnce() {
18 procs := runtime.GOMAXPROCS(-1)
19 compl := make(chan uint64, procs)
20 once := &sync.Once{}
21 for p := 0; p != procs; p += 1 {
22 go func() {
23 f := func() {}
24 work := uint64(0)
25 for benchmarking {
26 work += 1
27 if (work % 1000) == 0 {
28 runtime.Gosched()
29 }
30 once.Do(f)
31 }
32 compl <- work
33 }()
34 }
35 for p := 0; p != procs; p += 1 {
36 totalWork += <-compl
37 }
38 }
39
40 func SuiteOnce(benchmarks *vector.Vector) {
41 benchmarks.Push(&Benchmark{"once", benchmarkOnce})
42 }
OLDNEW
« no previous file with comments | « test/scale/mutex.go ('k') | test/scale/pingpong.go » ('j') | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b