This repository has been archived by the owner on Sep 7, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
bench_test.go
82 lines (68 loc) · 1.49 KB
/
bench_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
82
package num
import (
"math/big"
"testing"
)
var (
BenchBigFloatResult *big.Float
BenchBigIntResult *big.Int
BenchBoolResult bool
BenchFloatResult float64
BenchIntResult int
BenchStringResult string
BenchU128Result U128
BenchUint64Result uint64
BenchUint641, BenchUint642 uint64 = 12093749018, 18927348917
)
func BenchmarkUint64Mul(b *testing.B) {
for i := 0; i < b.N; i++ {
BenchUint64Result = BenchUint641 * BenchUint642
}
}
func BenchmarkUint64Add(b *testing.B) {
for i := 0; i < b.N; i++ {
BenchUint64Result = BenchUint641 + BenchUint642
}
}
func BenchmarkUint64Div(b *testing.B) {
for i := 0; i < b.N; i++ {
BenchUint64Result = BenchUint641 / BenchUint642
}
}
func BenchmarkUint64Equal(b *testing.B) {
for i := 0; i < b.N; i++ {
BenchBoolResult = BenchUint641 == BenchUint642
}
}
func BenchmarkBigIntMul(b *testing.B) {
var max big.Int
max.SetUint64(maxUint64)
for i := 0; i < b.N; i++ {
var dest big.Int
dest.Mul(&dest, &max)
}
}
func BenchmarkBigIntAdd(b *testing.B) {
var max big.Int
max.SetUint64(maxUint64)
for i := 0; i < b.N; i++ {
var dest big.Int
dest.Add(&dest, &max)
}
}
func BenchmarkBigIntDiv(b *testing.B) {
u := new(big.Int).SetUint64(maxUint64)
by := new(big.Int).SetUint64(121525124)
for i := 0; i < b.N; i++ {
var z big.Int
z.Div(u, by)
}
}
func BenchmarkBigIntCmpEqual(b *testing.B) {
var v1, v2 big.Int
v1.SetUint64(maxUint64)
v2.SetUint64(maxUint64)
for i := 0; i < b.N; i++ {
BenchIntResult = v1.Cmp(&v2)
}
}