-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathmath_bench_test.go
61 lines (54 loc) · 1.35 KB
/
math_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
package zenodb
import (
"encoding/binary"
"math"
"testing"
)
func BenchmarkMathFloatBigEndian(b *testing.B) {
buf := make([]byte, 8)
b.ResetTimer()
for i := 0; i < b.N; i++ {
f := math.Float64frombits(binary.BigEndian.Uint64(buf))
binary.BigEndian.PutUint64(buf, math.Float64bits(f+1))
}
}
func BenchmarkMathFloatLittleEndian(b *testing.B) {
buf := make([]byte, 8)
b.ResetTimer()
for i := 0; i < b.N; i++ {
f := math.Float64frombits(binary.LittleEndian.Uint64(buf))
binary.LittleEndian.PutUint64(buf, math.Float64bits(f+1))
}
}
func BenchmarkMathIntBigEndian(b *testing.B) {
buf := make([]byte, 8)
b.ResetTimer()
for i := 0; i < b.N; i++ {
f := int64(binary.BigEndian.Uint64(buf))
binary.BigEndian.PutUint64(buf, uint64(f+1))
}
}
func BenchmarkMathIntLittleEndian(b *testing.B) {
buf := make([]byte, 8)
b.ResetTimer()
for i := 0; i < b.N; i++ {
f := int64(binary.LittleEndian.Uint64(buf))
binary.LittleEndian.PutUint64(buf, uint64(f+1))
}
}
func BenchmarkMathUintBigEndian(b *testing.B) {
buf := make([]byte, 8)
b.ResetTimer()
for i := 0; i < b.N; i++ {
f := binary.BigEndian.Uint64(buf)
binary.BigEndian.PutUint64(buf, f+1)
}
}
func BenchmarkMathUintLittleEndian(b *testing.B) {
buf := make([]byte, 8)
b.ResetTimer()
for i := 0; i < b.N; i++ {
f := binary.LittleEndian.Uint64(buf)
binary.LittleEndian.PutUint64(buf, f+1)
}
}