-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfloat_encode_bench_test.go
More file actions
61 lines (55 loc) · 1.24 KB
/
Copy pathfloat_encode_bench_test.go
File metadata and controls
61 lines (55 loc) · 1.24 KB
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 jsonx
import (
"strconv"
"testing"
)
var canadaSamples = []float64{
-65.613616999999977, 43.420273000000009, -65.619720000000029,
43.418052999999986, -65.625, 43.421379000000059,
-65.636123999999882, 43.449714999999969, -65.633056999999951,
43.474709000000132, -65.642776999999915, 43.481938,
}
func BenchmarkFloatShortestF(b *testing.B) {
buf := make([]byte, 0, 64)
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {
for _, v := range canadaSamples {
buf = strconv.AppendFloat(buf[:0], v, 'f', -1, 64)
}
}
_ = buf
}
func BenchmarkFloatGPrec17(b *testing.B) {
buf := make([]byte, 0, 64)
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {
for _, v := range canadaSamples {
buf = strconv.AppendFloat(buf[:0], v, 'g', 17, 64)
}
}
_ = buf
}
func BenchmarkFloatEPrec17(b *testing.B) {
buf := make([]byte, 0, 64)
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {
for _, v := range canadaSamples {
buf = strconv.AppendFloat(buf[:0], v, 'e', 17, 64)
}
}
_ = buf
}
func BenchmarkFloatSchubfach(b *testing.B) {
buf := make([]byte, 0, 64)
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {
for _, v := range canadaSamples {
buf = schubfachAppendFloat64(buf[:0], v)
}
}
_ = buf
}