mirror of
https://github.com/golang/go
synced 2024-11-18 10:04:43 -07:00
math/big: added benchmarks to establish baseline for core functions
BenchmarkAddVV_1 500000000 7.24 ns/op 8844.11 MB/s BenchmarkAddVV_2 100000000 10.4 ns/op 12290.41 MB/s BenchmarkAddVV_3 100000000 10.7 ns/op 17966.58 MB/s BenchmarkAddVV_4 100000000 12.3 ns/op 20848.67 MB/s BenchmarkAddVV_5 100000000 14.5 ns/op 21993.82 MB/s BenchmarkAddVV_1e1 100000000 24.0 ns/op 26720.65 MB/s BenchmarkAddVV_1e2 10000000 246 ns/op 26014.58 MB/s BenchmarkAddVV_1e3 1000000 2416 ns/op 26485.06 MB/s BenchmarkAddVV_1e4 100000 23874 ns/op 26806.36 MB/s BenchmarkAddVV_1e5 10000 241155 ns/op 26538.87 MB/s BenchmarkAddVW_1 500000000 6.12 ns/op 10461.91 MB/s BenchmarkAddVW_2 200000000 11.0 ns/op 11596.63 MB/s BenchmarkAddVW_3 200000000 8.97 ns/op 21409.82 MB/s BenchmarkAddVW_4 100000000 10.8 ns/op 23696.72 MB/s BenchmarkAddVW_5 100000000 12.5 ns/op 25524.88 MB/s BenchmarkAddVW_1e1 100000000 21.5 ns/op 29786.32 MB/s BenchmarkAddVW_1e2 10000000 168 ns/op 37925.36 MB/s BenchmarkAddVW_1e3 1000000 1658 ns/op 38579.15 MB/s BenchmarkAddVW_1e4 100000 16492 ns/op 38805.85 MB/s BenchmarkAddVW_1e5 10000 172155 ns/op 37175.69 MB/s BenchmarkAddMulVVW_1 100000000 12.9 ns/op 4968.49 MB/s BenchmarkAddMulVVW_2 100000000 15.5 ns/op 8279.42 MB/s BenchmarkAddMulVVW_3 100000000 13.4 ns/op 14340.53 MB/s BenchmarkAddMulVVW_4 100000000 15.8 ns/op 16194.94 MB/s BenchmarkAddMulVVW_5 100000000 18.9 ns/op 16906.61 MB/s BenchmarkAddMulVVW_1e1 50000000 32.3 ns/op 19838.35 MB/s BenchmarkAddMulVVW_1e2 10000000 285 ns/op 22427.28 MB/s BenchmarkAddMulVVW_1e3 1000000 2777 ns/op 23040.42 MB/s BenchmarkAddMulVVW_1e4 100000 27901 ns/op 22938.01 MB/s BenchmarkAddMulVVW_1e5 10000 281087 ns/op 22768.73 MB/s R=r CC=golang-dev https://golang.org/cl/6478055
This commit is contained in:
parent
0a115d72c1
commit
053b448d61
@ -4,7 +4,10 @@
|
||||
|
||||
package big
|
||||
|
||||
import "testing"
|
||||
import (
|
||||
"math/rand"
|
||||
"testing"
|
||||
)
|
||||
|
||||
type funWW func(x, y, c Word) (z1, z0 Word)
|
||||
type argWW struct {
|
||||
@ -100,6 +103,43 @@ func TestFunVV(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// Always the same seed for reproducible results.
|
||||
var rnd = rand.New(rand.NewSource(0))
|
||||
|
||||
func rndW() Word {
|
||||
return Word(rnd.Int63()<<1 | rnd.Int63n(2))
|
||||
}
|
||||
|
||||
func rndV(n int) []Word {
|
||||
v := make([]Word, n)
|
||||
for i := range v {
|
||||
v[i] = rndW()
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
func benchmarkFunVV(b *testing.B, f funVV, n int) {
|
||||
x := rndV(n)
|
||||
y := rndV(n)
|
||||
z := make([]Word, n)
|
||||
b.SetBytes(int64(n * _W))
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
f(z, x, y)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkAddVV_1(b *testing.B) { benchmarkFunVV(b, addVV, 1) }
|
||||
func BenchmarkAddVV_2(b *testing.B) { benchmarkFunVV(b, addVV, 2) }
|
||||
func BenchmarkAddVV_3(b *testing.B) { benchmarkFunVV(b, addVV, 3) }
|
||||
func BenchmarkAddVV_4(b *testing.B) { benchmarkFunVV(b, addVV, 4) }
|
||||
func BenchmarkAddVV_5(b *testing.B) { benchmarkFunVV(b, addVV, 5) }
|
||||
func BenchmarkAddVV_1e1(b *testing.B) { benchmarkFunVV(b, addVV, 1e1) }
|
||||
func BenchmarkAddVV_1e2(b *testing.B) { benchmarkFunVV(b, addVV, 1e2) }
|
||||
func BenchmarkAddVV_1e3(b *testing.B) { benchmarkFunVV(b, addVV, 1e3) }
|
||||
func BenchmarkAddVV_1e4(b *testing.B) { benchmarkFunVV(b, addVV, 1e4) }
|
||||
func BenchmarkAddVV_1e5(b *testing.B) { benchmarkFunVV(b, addVV, 1e5) }
|
||||
|
||||
type funVW func(z, x []Word, y Word) (c Word)
|
||||
type argVW struct {
|
||||
z, x nat
|
||||
@ -210,6 +250,28 @@ func TestFunVW(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func benchmarkFunVW(b *testing.B, f funVW, n int) {
|
||||
x := rndV(n)
|
||||
y := rndW()
|
||||
z := make([]Word, n)
|
||||
b.SetBytes(int64(n * _W))
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
f(z, x, y)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkAddVW_1(b *testing.B) { benchmarkFunVW(b, addVW, 1) }
|
||||
func BenchmarkAddVW_2(b *testing.B) { benchmarkFunVW(b, addVW, 2) }
|
||||
func BenchmarkAddVW_3(b *testing.B) { benchmarkFunVW(b, addVW, 3) }
|
||||
func BenchmarkAddVW_4(b *testing.B) { benchmarkFunVW(b, addVW, 4) }
|
||||
func BenchmarkAddVW_5(b *testing.B) { benchmarkFunVW(b, addVW, 5) }
|
||||
func BenchmarkAddVW_1e1(b *testing.B) { benchmarkFunVW(b, addVW, 1e1) }
|
||||
func BenchmarkAddVW_1e2(b *testing.B) { benchmarkFunVW(b, addVW, 1e2) }
|
||||
func BenchmarkAddVW_1e3(b *testing.B) { benchmarkFunVW(b, addVW, 1e3) }
|
||||
func BenchmarkAddVW_1e4(b *testing.B) { benchmarkFunVW(b, addVW, 1e4) }
|
||||
func BenchmarkAddVW_1e5(b *testing.B) { benchmarkFunVW(b, addVW, 1e5) }
|
||||
|
||||
type funVWW func(z, x []Word, y, r Word) (c Word)
|
||||
type argVWW struct {
|
||||
z, x nat
|
||||
@ -334,6 +396,28 @@ func TestMulAddWWW(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func benchmarkAddMulVVW(b *testing.B, n int) {
|
||||
x := rndV(n)
|
||||
y := rndW()
|
||||
z := make([]Word, n)
|
||||
b.SetBytes(int64(n * _W))
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
addMulVVW(z, x, y)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkAddMulVVW_1(b *testing.B) { benchmarkAddMulVVW(b, 1) }
|
||||
func BenchmarkAddMulVVW_2(b *testing.B) { benchmarkAddMulVVW(b, 2) }
|
||||
func BenchmarkAddMulVVW_3(b *testing.B) { benchmarkAddMulVVW(b, 3) }
|
||||
func BenchmarkAddMulVVW_4(b *testing.B) { benchmarkAddMulVVW(b, 4) }
|
||||
func BenchmarkAddMulVVW_5(b *testing.B) { benchmarkAddMulVVW(b, 5) }
|
||||
func BenchmarkAddMulVVW_1e1(b *testing.B) { benchmarkAddMulVVW(b, 1e1) }
|
||||
func BenchmarkAddMulVVW_1e2(b *testing.B) { benchmarkAddMulVVW(b, 1e2) }
|
||||
func BenchmarkAddMulVVW_1e3(b *testing.B) { benchmarkAddMulVVW(b, 1e3) }
|
||||
func BenchmarkAddMulVVW_1e4(b *testing.B) { benchmarkAddMulVVW(b, 1e4) }
|
||||
func BenchmarkAddMulVVW_1e5(b *testing.B) { benchmarkAddMulVVW(b, 1e5) }
|
||||
|
||||
func testWordBitLen(t *testing.T, fname string, f func(Word) int) {
|
||||
for i := 0; i <= _W; i++ {
|
||||
x := Word(1) << uint(i-1) // i == 0 => x == 0
|
||||
|
@ -6,7 +6,6 @@ package big
|
||||
|
||||
import (
|
||||
"io"
|
||||
"math/rand"
|
||||
"runtime"
|
||||
"strings"
|
||||
"testing"
|
||||
@ -192,19 +191,14 @@ func TestMulUnbalanced(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
var rnd = rand.New(rand.NewSource(0x43de683f473542af))
|
||||
var mulx = rndNat(1e4)
|
||||
var muly = rndNat(1e4)
|
||||
|
||||
func rndNat(n int) nat {
|
||||
x := make(nat, n)
|
||||
for i := 0; i < n; i++ {
|
||||
x[i] = Word(rnd.Int63()<<1 + rnd.Int63n(2))
|
||||
}
|
||||
return x.norm()
|
||||
return nat(rndV(n)).norm()
|
||||
}
|
||||
|
||||
func BenchmarkMul(b *testing.B) {
|
||||
mulx := rndNat(1e4)
|
||||
muly := rndNat(1e4)
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
var z nat
|
||||
z.mul(mulx, muly)
|
||||
|
Loading…
Reference in New Issue
Block a user