From bb9531e11ba964fa5f8df2404fea8606a4a43b1d Mon Sep 17 00:00:00 2001 From: Dmitriy Vyukov Date: Mon, 24 Feb 2014 20:47:17 +0400 Subject: [PATCH] time: use RunParallel in benchmarks LGTM=bradfitz R=golang-codereviews, bradfitz CC=golang-codereviews https://golang.org/cl/68060043 --- src/pkg/time/sleep_test.go | 23 +++++------------------ 1 file changed, 5 insertions(+), 18 deletions(-) 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++ { -- 2.48.1