Commit 2deb9209 authored by Marcel van Lohuizen's avatar Marcel van Lohuizen

math/big: using Run for some more benchmarks

Change-Id: I3ede8098f405de5d88e51c8370d3b68446d40744
Reviewed-on: https://go-review.googlesource.com/23428
Run-TryBot: Marcel van Lohuizen <mpvl@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarRobert Griesemer <gri@golang.org>
parent bfccf407
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
package big package big
import ( import (
"fmt"
"runtime" "runtime"
"strings" "strings"
"testing" "testing"
...@@ -509,24 +510,20 @@ func TestExpNN(t *testing.T) { ...@@ -509,24 +510,20 @@ func TestExpNN(t *testing.T) {
} }
} }
func ExpHelper(b *testing.B, x, y Word) { func BenchmarkExp3Power(b *testing.B) {
const x = 3
for _, y := range []Word{
0x10, 0x40, 0x100, 0x400, 0x1000, 0x4000, 0x10000, 0x40000, 0x100000, 0x400000,
} {
b.Run(fmt.Sprintf("%#x", y), func(b *testing.B) {
var z nat var z nat
for i := 0; i < b.N; i++ { for i := 0; i < b.N; i++ {
z.expWW(x, y) z.expWW(x, y)
} }
})
}
} }
func BenchmarkExp3Power0x10(b *testing.B) { ExpHelper(b, 3, 0x10) }
func BenchmarkExp3Power0x40(b *testing.B) { ExpHelper(b, 3, 0x40) }
func BenchmarkExp3Power0x100(b *testing.B) { ExpHelper(b, 3, 0x100) }
func BenchmarkExp3Power0x400(b *testing.B) { ExpHelper(b, 3, 0x400) }
func BenchmarkExp3Power0x1000(b *testing.B) { ExpHelper(b, 3, 0x1000) }
func BenchmarkExp3Power0x4000(b *testing.B) { ExpHelper(b, 3, 0x4000) }
func BenchmarkExp3Power0x10000(b *testing.B) { ExpHelper(b, 3, 0x10000) }
func BenchmarkExp3Power0x40000(b *testing.B) { ExpHelper(b, 3, 0x40000) }
func BenchmarkExp3Power0x100000(b *testing.B) { ExpHelper(b, 3, 0x100000) }
func BenchmarkExp3Power0x400000(b *testing.B) { ExpHelper(b, 3, 0x400000) }
func fibo(n int) nat { func fibo(n int) nat {
switch n { switch n {
case 0: case 0:
......
...@@ -6,6 +6,7 @@ package big ...@@ -6,6 +6,7 @@ package big
import ( import (
"bytes" "bytes"
"fmt"
"io" "io"
"strings" "strings"
"testing" "testing"
...@@ -273,31 +274,11 @@ func BenchmarkStringPiParallel(b *testing.B) { ...@@ -273,31 +274,11 @@ func BenchmarkStringPiParallel(b *testing.B) {
}) })
} }
func BenchmarkScan10Base2(b *testing.B) { ScanHelper(b, 2, 10, 10) } func BenchmarkScan(b *testing.B) {
func BenchmarkScan100Base2(b *testing.B) { ScanHelper(b, 2, 10, 100) } const x = 10
func BenchmarkScan1000Base2(b *testing.B) { ScanHelper(b, 2, 10, 1000) } for _, base := range []int{2, 8, 10, 16} {
func BenchmarkScan10000Base2(b *testing.B) { ScanHelper(b, 2, 10, 10000) } for _, y := range []Word{10, 100, 1000, 10000, 100000} {
func BenchmarkScan100000Base2(b *testing.B) { ScanHelper(b, 2, 10, 100000) } b.Run(fmt.Sprintf("%d/Base%d", y, base), func(b *testing.B) {
func BenchmarkScan10Base8(b *testing.B) { ScanHelper(b, 8, 10, 10) }
func BenchmarkScan100Base8(b *testing.B) { ScanHelper(b, 8, 10, 100) }
func BenchmarkScan1000Base8(b *testing.B) { ScanHelper(b, 8, 10, 1000) }
func BenchmarkScan10000Base8(b *testing.B) { ScanHelper(b, 8, 10, 10000) }
func BenchmarkScan100000Base8(b *testing.B) { ScanHelper(b, 8, 10, 100000) }
func BenchmarkScan10Base10(b *testing.B) { ScanHelper(b, 10, 10, 10) }
func BenchmarkScan100Base10(b *testing.B) { ScanHelper(b, 10, 10, 100) }
func BenchmarkScan1000Base10(b *testing.B) { ScanHelper(b, 10, 10, 1000) }
func BenchmarkScan10000Base10(b *testing.B) { ScanHelper(b, 10, 10, 10000) }
func BenchmarkScan100000Base10(b *testing.B) { ScanHelper(b, 10, 10, 100000) }
func BenchmarkScan10Base16(b *testing.B) { ScanHelper(b, 16, 10, 10) }
func BenchmarkScan100Base16(b *testing.B) { ScanHelper(b, 16, 10, 100) }
func BenchmarkScan1000Base16(b *testing.B) { ScanHelper(b, 16, 10, 1000) }
func BenchmarkScan10000Base16(b *testing.B) { ScanHelper(b, 16, 10, 10000) }
func BenchmarkScan100000Base16(b *testing.B) { ScanHelper(b, 16, 10, 100000) }
func ScanHelper(b *testing.B, base int, x, y Word) {
b.StopTimer() b.StopTimer()
var z nat var z nat
z = z.expWW(x, y) z = z.expWW(x, y)
...@@ -311,33 +292,16 @@ func ScanHelper(b *testing.B, base int, x, y Word) { ...@@ -311,33 +292,16 @@ func ScanHelper(b *testing.B, base int, x, y Word) {
for i := 0; i < b.N; i++ { for i := 0; i < b.N; i++ {
z.scan(bytes.NewReader(s), base, false) z.scan(bytes.NewReader(s), base, false)
} }
})
}
}
} }
func BenchmarkString10Base2(b *testing.B) { StringHelper(b, 2, 10, 10) } func BenchmarkString(b *testing.B) {
func BenchmarkString100Base2(b *testing.B) { StringHelper(b, 2, 10, 100) } const x = 10
func BenchmarkString1000Base2(b *testing.B) { StringHelper(b, 2, 10, 1000) } for _, base := range []int{2, 8, 10, 16} {
func BenchmarkString10000Base2(b *testing.B) { StringHelper(b, 2, 10, 10000) } for _, y := range []Word{10, 100, 1000, 10000, 100000} {
func BenchmarkString100000Base2(b *testing.B) { StringHelper(b, 2, 10, 100000) } b.Run(fmt.Sprintf("%d/Base%d", y, base), func(b *testing.B) {
func BenchmarkString10Base8(b *testing.B) { StringHelper(b, 8, 10, 10) }
func BenchmarkString100Base8(b *testing.B) { StringHelper(b, 8, 10, 100) }
func BenchmarkString1000Base8(b *testing.B) { StringHelper(b, 8, 10, 1000) }
func BenchmarkString10000Base8(b *testing.B) { StringHelper(b, 8, 10, 10000) }
func BenchmarkString100000Base8(b *testing.B) { StringHelper(b, 8, 10, 100000) }
func BenchmarkString10Base10(b *testing.B) { StringHelper(b, 10, 10, 10) }
func BenchmarkString100Base10(b *testing.B) { StringHelper(b, 10, 10, 100) }
func BenchmarkString1000Base10(b *testing.B) { StringHelper(b, 10, 10, 1000) }
func BenchmarkString10000Base10(b *testing.B) { StringHelper(b, 10, 10, 10000) }
func BenchmarkString100000Base10(b *testing.B) { StringHelper(b, 10, 10, 100000) }
func BenchmarkString10Base16(b *testing.B) { StringHelper(b, 16, 10, 10) }
func BenchmarkString100Base16(b *testing.B) { StringHelper(b, 16, 10, 100) }
func BenchmarkString1000Base16(b *testing.B) { StringHelper(b, 16, 10, 1000) }
func BenchmarkString10000Base16(b *testing.B) { StringHelper(b, 16, 10, 10000) }
func BenchmarkString100000Base16(b *testing.B) { StringHelper(b, 16, 10, 100000) }
func StringHelper(b *testing.B, base int, x, y Word) {
b.StopTimer() b.StopTimer()
var z nat var z nat
z = z.expWW(x, y) z = z.expWW(x, y)
...@@ -347,27 +311,20 @@ func StringHelper(b *testing.B, base int, x, y Word) { ...@@ -347,27 +311,20 @@ func StringHelper(b *testing.B, base int, x, y Word) {
for i := 0; i < b.N; i++ { for i := 0; i < b.N; i++ {
_ = z.utoa(base) _ = z.utoa(base)
} }
})
}
}
} }
func BenchmarkLeafSize0(b *testing.B) { LeafSizeHelper(b, 10, 0) } // test without splitting func BenchmarkLeafSize(b *testing.B) {
func BenchmarkLeafSize1(b *testing.B) { LeafSizeHelper(b, 10, 1) } for n := 0; n <= 16; n++ {
func BenchmarkLeafSize2(b *testing.B) { LeafSizeHelper(b, 10, 2) } b.Run(fmt.Sprint(n), func(b *testing.B) { LeafSizeHelper(b, 10, n) })
func BenchmarkLeafSize3(b *testing.B) { LeafSizeHelper(b, 10, 3) } }
func BenchmarkLeafSize4(b *testing.B) { LeafSizeHelper(b, 10, 4) } // Try some large lengths
func BenchmarkLeafSize5(b *testing.B) { LeafSizeHelper(b, 10, 5) } for _, n := range []int{32, 64} {
func BenchmarkLeafSize6(b *testing.B) { LeafSizeHelper(b, 10, 6) } b.Run(fmt.Sprint(n), func(b *testing.B) { LeafSizeHelper(b, 10, n) })
func BenchmarkLeafSize7(b *testing.B) { LeafSizeHelper(b, 10, 7) } }
func BenchmarkLeafSize8(b *testing.B) { LeafSizeHelper(b, 10, 8) } }
func BenchmarkLeafSize9(b *testing.B) { LeafSizeHelper(b, 10, 9) }
func BenchmarkLeafSize10(b *testing.B) { LeafSizeHelper(b, 10, 10) }
func BenchmarkLeafSize11(b *testing.B) { LeafSizeHelper(b, 10, 11) }
func BenchmarkLeafSize12(b *testing.B) { LeafSizeHelper(b, 10, 12) }
func BenchmarkLeafSize13(b *testing.B) { LeafSizeHelper(b, 10, 13) }
func BenchmarkLeafSize14(b *testing.B) { LeafSizeHelper(b, 10, 14) }
func BenchmarkLeafSize15(b *testing.B) { LeafSizeHelper(b, 10, 15) }
func BenchmarkLeafSize16(b *testing.B) { LeafSizeHelper(b, 10, 16) }
func BenchmarkLeafSize32(b *testing.B) { LeafSizeHelper(b, 10, 32) } // try some large lengths
func BenchmarkLeafSize64(b *testing.B) { LeafSizeHelper(b, 10, 64) }
func LeafSizeHelper(b *testing.B, base, size int) { func LeafSizeHelper(b *testing.B, base, size int) {
b.StopTimer() b.StopTimer()
......
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