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

src/pkg/math/big/nat_test.go

index 1d4dfe80d3d66479d0f013ed6015b4d1fff63b32..f7105b09989a6efd1c4fd54f7df05d3b409317cb 100644 (file)
@@ -437,20 +437,11 @@ func BenchmarkStringPiParallel(b *testing.B) {
        if x.decimalString() != pi {
                panic("benchmark incorrect: conversion failed")
        }
-       n := runtime.GOMAXPROCS(0)
-       m := b.N / n // n*m <= b.N due to flooring, but the error is neglibible (n is not very large)
-       c := make(chan int, n)
-       for i := 0; i < n; i++ {
-               go func() {
-                       for j := 0; j < m; j++ {
-                               x.decimalString()
-                       }
-                       c <- 0
-               }()
-       }
-       for i := 0; i < n; i++ {
-               <-c
-       }
+       b.RunParallel(func(pb *testing.PB) {
+               for pb.Next() {
+                       x.decimalString()
+               }
+       })
 }
 
 func BenchmarkScan10Base2(b *testing.B)     { ScanHelper(b, 2, 10, 10) }