Commit f6cdfc79 authored by Alberto Donizetti's avatar Alberto Donizetti Committed by Brad Fitzpatrick

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/31275Reviewed-by: default avatarBrad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent 57666c3f
......@@ -4,7 +4,10 @@
package big
import "testing"
import (
"fmt"
"testing"
)
func TestDecimalString(t *testing.T) {
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()
}
})
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment