From 51b9879a905f35c4572d7cbaa4179b05970de7f5 Mon Sep 17 00:00:00 2001 From: Dmitriy Vyukov Date: Mon, 24 Feb 2014 20:46:56 +0400 Subject: [PATCH] math/big: use RunParallel in benchmarks LGTM=bradfitz R=golang-codereviews, bradfitz CC=golang-codereviews https://golang.org/cl/67830044 --- src/pkg/math/big/nat_test.go | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/src/pkg/math/big/nat_test.go b/src/pkg/math/big/nat_test.go index 1d4dfe80d3d..f7105b09989 100644 --- a/src/pkg/math/big/nat_test.go +++ b/src/pkg/math/big/nat_test.go @@ -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) }