-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
float_test.go
88 lines (73 loc) · 1.25 KB
/
float_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
package gocostmodel
import (
"math"
"testing"
)
var (
f1 float32 = 1.23
f2 float32 = 3.45
f3 float32 = 6.78
d1 float64 = 1.23
d2 float64 = 3.45
d3 float64 = 6.78
)
func BenchmarkFloat32Assign(b *testing.B) {
for i := 0; i < b.N; i++ {
f1 = f2
}
}
func BenchmarkFloat32Inc(b *testing.B) {
for i := 0; i < b.N; i++ {
f1++
}
}
func BenchmarkFloat32Add(b *testing.B) {
for i := 0; i < b.N; i++ {
f1 = f2 + f3
}
}
func BenchmarkFloat32Sub(b *testing.B) {
for i := 0; i < b.N; i++ {
f1 = f2 - f3
}
}
func BenchmarkFloat32Mul(b *testing.B) {
for i := 0; i < b.N; i++ {
f1 = f2 * f3
}
}
func BenchmarkFloat32Mod(b *testing.B) {
for i := 0; i < b.N; i++ {
f1 = float32(math.Mod(float64(f2), float64(f3)))
}
}
func BenchmarkFloat64Assign(b *testing.B) {
for i := 0; i < b.N; i++ {
d1 = d2
}
}
func BenchmarkFloat64Inc(b *testing.B) {
for i := 0; i < b.N; i++ {
d1++
}
}
func BenchmarkFloat64Add(b *testing.B) {
for i := 0; i < b.N; i++ {
d1 = d2 + d3
}
}
func BenchmarkFloat64Sub(b *testing.B) {
for i := 0; i < b.N; i++ {
d1 = d2 - d3
}
}
func BenchmarkFloat64Mul(b *testing.B) {
for i := 0; i < b.N; i++ {
d1 = d2 * d3
}
}
func BenchmarkFloat64Mod(b *testing.B) {
for i := 0; i < b.N; i++ {
d1 = math.Mod(d2, d3)
}
}