diff options
| author | Michael Stapelberg <stapelberg@debian.org> | 2014-06-19 09:22:53 +0200 |
|---|---|---|
| committer | Michael Stapelberg <stapelberg@debian.org> | 2014-06-19 09:22:53 +0200 |
| commit | 8a39ee361feb9bf46d728ff1ba4f07ca1d9610b1 (patch) | |
| tree | 4449f2036cccf162e8417cc5841a35815b3e7ac5 /src/pkg/sync/once_test.go | |
| parent | c8bf49ef8a92e2337b69c14b9b88396efe498600 (diff) | |
| download | golang-51f2ca399fb8da86b2e7b3a0582e083fab731a98.tar.gz | |
Imported Upstream version 1.3upstream/1.3
Diffstat (limited to 'src/pkg/sync/once_test.go')
| -rw-r--r-- | src/pkg/sync/once_test.go | 25 |
1 files changed, 5 insertions, 20 deletions
diff --git a/src/pkg/sync/once_test.go b/src/pkg/sync/once_test.go index 183069a1a..8afda82f3 100644 --- a/src/pkg/sync/once_test.go +++ b/src/pkg/sync/once_test.go @@ -5,9 +5,7 @@ package sync_test import ( - "runtime" . "sync" - "sync/atomic" "testing" ) @@ -62,24 +60,11 @@ func TestOncePanic(t *testing.T) { } func BenchmarkOnce(b *testing.B) { - const CallsPerSched = 1000 - procs := runtime.GOMAXPROCS(-1) - N := int32(b.N / CallsPerSched) var once Once f := func() {} - c := make(chan bool, procs) - for p := 0; p < procs; p++ { - go func() { - for atomic.AddInt32(&N, -1) >= 0 { - runtime.Gosched() - for g := 0; g < CallsPerSched; g++ { - once.Do(f) - } - } - c <- true - }() - } - for p := 0; p < procs; p++ { - <-c - } + b.RunParallel(func(pb *testing.PB) { + for pb.Next() { + once.Do(f) + } + }) } |
