From: Dmitriy Vyukov Date: Mon, 24 Feb 2014 16:47:17 +0000 (+0400) Subject: time: use RunParallel in benchmarks X-Git-Tag: go1.3beta1~605 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=bb9531e11ba964fa5f8df2404fea8606a4a43b1d;p=gostls13.git time: use RunParallel in benchmarks LGTM=bradfitz R=golang-codereviews, bradfitz CC=golang-codereviews https://golang.org/cl/68060043 --- diff --git a/src/pkg/time/sleep_test.go b/src/pkg/time/sleep_test.go index 23cb3daebb..ce2dc36322 100644 --- a/src/pkg/time/sleep_test.go +++ b/src/pkg/time/sleep_test.go @@ -74,26 +74,13 @@ func benchmark(b *testing.B, bench func(n int)) { for i := 0; i < len(garbage); i++ { garbage[i] = AfterFunc(Hour, nil) } - - const batch = 1000 - P := runtime.GOMAXPROCS(-1) - N := int32(b.N / batch) - b.ResetTimer() - var wg sync.WaitGroup - wg.Add(P) - - for p := 0; p < P; p++ { - go func() { - for atomic.AddInt32(&N, -1) >= 0 { - bench(batch) - } - wg.Done() - }() - } - - wg.Wait() + b.RunParallel(func(pb *testing.PB) { + for pb.Next() { + bench(1000) + } + }) b.StopTimer() for i := 0; i < len(garbage); i++ {