]> Cypherpunks repositories - gostls13.git/commitdiff
time: use RunParallel in benchmarks
authorDmitriy Vyukov <dvyukov@google.com>
Mon, 24 Feb 2014 16:47:17 +0000 (20:47 +0400)
committerDmitriy Vyukov <dvyukov@google.com>
Mon, 24 Feb 2014 16:47:17 +0000 (20:47 +0400)
LGTM=bradfitz
R=golang-codereviews, bradfitz
CC=golang-codereviews
https://golang.org/cl/68060043

src/pkg/time/sleep_test.go

index 23cb3daebbf35493cb8fcc7bb0de97c39d26943c..ce2dc363222804242eb1252f1acf7da7d6a54fe0 100644 (file)
@@ -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++ {