-
Notifications
You must be signed in to change notification settings - Fork 1
/
main_test.go
103 lines (93 loc) · 2.57 KB
/
main_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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
package main
import (
"github.com/sineycoder/go-bigger/bigger"
"github.com/sineycoder/go-bigger/types"
"math/big"
"testing"
)
/**
@author: nizhenxian
@date: 2021/8/18 11:29:54
**/
// testing Integer, bigger.bigInteger vs bigInt
func BenchmarkBiggerIntegerAdd(bb *testing.B) {
a := bigger.BigIntegerValueOf(types.Long(534151451245))
b := bigger.BigIntegerValueOf(types.Long(18979412))
a.Add(b)
}
func BenchmarkBigintIntegerAdd(bb *testing.B) {
a := big.NewInt(534151451245)
b := big.NewInt(18979412)
a.Add(a, b)
}
func BenchmarkBiggerIntegerSubtract(bb *testing.B) {
a := bigger.BigIntegerValueOf(types.Long(534151451245))
b := bigger.BigIntegerValueOf(types.Long(18979412))
a.Subtract(b)
}
func BenchmarkBigintIntegerSubtract(bb *testing.B) {
a := big.NewInt(534151451245)
b := big.NewInt(18979412)
a.Sub(a, b)
}
func BenchmarkBiggerIntegerMultiply(bb *testing.B) {
a := bigger.BigIntegerValueOf(types.Long(534151451245))
b := bigger.BigIntegerValueOf(types.Long(18979412))
a.Multiply(b)
}
func BenchmarkBigintIntegerMultiply(bb *testing.B) {
a := big.NewInt(534151451245)
b := big.NewInt(18979412)
a.Mul(a, b)
}
func BenchmarkBiggerIntegerDivide(bb *testing.B) {
a := bigger.BigIntegerValueOf(types.Long(534151451245))
b := bigger.BigIntegerValueOf(types.Long(18979412))
a.Divide(b)
}
func BenchmarkBigintIntegerDivide(bb *testing.B) {
a := big.NewInt(534151451245)
b := big.NewInt(18979412)
a.Div(a, b)
}
// testing Float, bigger.bigDecimal vs bigFloat
func BenchmarkBiggerFloatAdd(bb *testing.B) {
a := bigger.NewBigDecimalString("534151451245")
b := bigger.NewBigDecimalString("18979412")
a.Add(b)
}
func BenchmarkBigintFloatAdd(bb *testing.B) {
a := big.NewFloat(534151451245)
b := big.NewFloat(18979412)
a.Add(a, b)
}
func BenchmarkBiggerFloatSubtract(bb *testing.B) {
a := bigger.NewBigDecimalString("534151451245")
b := bigger.NewBigDecimalString("18979412")
a.Subtract(b)
}
func BenchmarkBigintFloatSubtract(bb *testing.B) {
a := big.NewFloat(534151451245)
b := big.NewFloat(18979412)
a.Sub(a, b)
}
func BenchmarkBiggerFloatMultiply(bb *testing.B) {
a := bigger.NewBigDecimalString("534151451245")
b := bigger.NewBigDecimalString("18979412")
a.Multiply(b)
}
func BenchmarkBigintFloatMultiply(bb *testing.B) {
a := big.NewFloat(534151451245)
b := big.NewFloat(18979412)
a.Mul(a, b)
}
func BenchmarkBiggerFloatDivide(bb *testing.B) {
a := bigger.NewBigDecimalString("1")
b := bigger.NewBigDecimalString("3")
a.Divide(b, 5, bigger.ROUND_HALF_UP)
}
func BenchmarkBigintFloatDivide(bb *testing.B) {
a := big.NewFloat(0.5)
b := big.NewFloat(0.4)
a.Quo(a, b)
}