1
0
mirror of https://github.com/golang/go synced 2024-11-18 14:44:41 -07:00

math/big: add benchmarks for big.Float String

In addition to the DecimalConversion benchmark, that exercises the
String method of the internal decimal type on a range of small shifts,
add a few benchmarks for the big.Float String method. They can be used
to obtain more realistic data on the real-world performance of
big.Float printing.

Change-Id: I7ada324e7603cb1ce7492ccaf3382db0096223ba
Reviewed-on: https://go-review.googlesource.com/31275
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
Alberto Donizetti 2016-10-17 21:59:10 +02:00 committed by Brad Fitzpatrick
parent 57666c3fe8
commit f6cdfc7987

View File

@ -4,7 +4,10 @@
package big package big
import "testing" import (
"fmt"
"testing"
)
func TestDecimalString(t *testing.T) { func TestDecimalString(t *testing.T) {
for _, test := range []struct { for _, test := range []struct {
@ -116,3 +119,16 @@ func BenchmarkDecimalConversion(b *testing.B) {
} }
} }
} }
func BenchmarkFloatString(b *testing.B) {
x := new(Float)
for _, prec := range []uint{1e2, 1e3, 1e4, 1e5} {
x.SetPrec(prec).SetRat(NewRat(1, 3))
b.Run(fmt.Sprintf("%v", prec), func(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
sink = x.String()
}
})
}
}