1
0
mirror of https://github.com/golang/go synced 2024-11-23 16:00:06 -07:00

math/big: use RunParallel in benchmarks

LGTM=bradfitz
R=golang-codereviews, bradfitz
CC=golang-codereviews
https://golang.org/cl/67830044
This commit is contained in:
Dmitriy Vyukov 2014-02-24 20:46:56 +04:00
parent 44cc8e5cc9
commit 51b9879a90

View 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) }