]> Cypherpunks repositories - gostls13.git/commitdiff
math/big: add benchmarks for big.Float String
authorAlberto Donizetti <alb.donizetti@gmail.com>
Mon, 17 Oct 2016 19:59:10 +0000 (21:59 +0200)
committerBrad Fitzpatrick <bradfitz@golang.org>
Tue, 18 Oct 2016 05:54:35 +0000 (05:54 +0000)
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>

src/math/big/decimal_test.go

index 13452f83436c56edf5c8e7fee995b78647674a04..424811e15af12d9fd1825803fa89dae7cd4436a1 100644 (file)
@@ -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()
+                       }
+               })
+       }
+}