-
-
Notifications
You must be signed in to change notification settings - Fork 26
/
bench_gmp_test.go
81 lines (75 loc) · 1.58 KB
/
bench_gmp_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package gmp
import (
"testing"
)
// Make a n digit number
func nDigitNumberGmp(digits int64) *Int {
x := NewInt(10)
n := NewInt(digits)
one := NewInt(1)
x.Exp(x, n, nil)
x.Sub(x, one)
return x
}
func benchmarkGmpAddN(b *testing.B, digits int64) {
x := nDigitNumberGmp(digits)
y := nDigitNumberGmp(digits)
z := NewInt(0)
b.ResetTimer()
b.StartTimer()
for i := b.N - 1; i >= 0; i-- {
z.Add(x, y)
}
}
func BenchmarkGmpAdd1(b *testing.B) {
benchmarkGmpAddN(b, 10)
}
func BenchmarkGmpAdd10(b *testing.B) {
benchmarkGmpAddN(b, 10)
}
func BenchmarkGmpAdd100(b *testing.B) {
benchmarkGmpAddN(b, 100)
}
func BenchmarkGmpAdd1000(b *testing.B) {
benchmarkGmpAddN(b, 1000)
}
func BenchmarkGmpAdd10000(b *testing.B) {
benchmarkGmpAddN(b, 10000)
}
func BenchmarkGmpAdd100000(b *testing.B) {
benchmarkGmpAddN(b, 100000)
}
func BenchmarkGmpAdd1000000(b *testing.B) {
benchmarkGmpAddN(b, 1000000)
}
func benchmarkGmpMulN(b *testing.B, digits int64) {
x := nDigitNumberGmp(digits)
y := nDigitNumberGmp(digits)
z := NewInt(0)
b.ResetTimer()
b.StartTimer()
for i := b.N - 1; i >= 0; i-- {
z.Mul(x, y)
}
}
func BenchmarkGmpMul1(b *testing.B) {
benchmarkGmpMulN(b, 10)
}
func BenchmarkGmpMul10(b *testing.B) {
benchmarkGmpMulN(b, 10)
}
func BenchmarkGmpMul100(b *testing.B) {
benchmarkGmpMulN(b, 100)
}
func BenchmarkGmpMul1000(b *testing.B) {
benchmarkGmpMulN(b, 1000)
}
func BenchmarkGmpMul10000(b *testing.B) {
benchmarkGmpMulN(b, 10000)
}
func BenchmarkGmpMul100000(b *testing.B) {
benchmarkGmpMulN(b, 100000)
}
func BenchmarkGmpMul1000000(b *testing.B) {
benchmarkGmpMulN(b, 1000000)
}