From f6cdfc7987d9f3ee7380b3e6f52e433608f342c5 Mon Sep 17 00:00:00 2001 From: Alberto Donizetti Date: Mon, 17 Oct 2016 21:59:10 +0200 Subject: [PATCH] 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 Run-TryBot: Brad Fitzpatrick TryBot-Result: Gobot Gobot --- src/math/big/decimal_test.go | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/math/big/decimal_test.go b/src/math/big/decimal_test.go index 13452f8343..424811e15a 100644 --- a/src/math/big/decimal_test.go +++ b/src/math/big/decimal_test.go @@ -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() + } + }) + } +}