-
Notifications
You must be signed in to change notification settings - Fork 106
/
benchmarks_test.go
115 lines (93 loc) · 2.2 KB
/
benchmarks_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
104
105
106
107
108
109
110
111
112
113
114
115
package wkt
import (
"encoding/json"
"io/ioutil"
"testing"
"github.com/paulmach/orb"
)
func BenchmarkUnmarshalPoint(b *testing.B) {
var mp orb.MultiPolygon
loadJSON(b, "testdata/polygon.json", &mp)
text := MarshalString(orb.Point{-81.60644531, 41.51377887})
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {
_, err := Unmarshal(text)
if err != nil {
b.Fatalf("unexpected error: %v", err)
}
}
}
func BenchmarkUnmarshalLineString_small(b *testing.B) {
ls := orb.LineString{{1, 2}, {3, 4}}
text := MarshalString(ls)
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {
_, err := Unmarshal(text)
if err != nil {
b.Fatalf("unexpected error: %v", err)
}
}
}
func BenchmarkUnmarshalLineString(b *testing.B) {
var mp orb.MultiPolygon
loadJSON(b, "testdata/polygon.json", &mp)
text := MarshalString(orb.LineString(mp[0][0]))
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {
_, err := Unmarshal(text)
if err != nil {
b.Fatalf("unexpected error: %v", err)
}
}
}
func BenchmarkUnmarshalPolygon(b *testing.B) {
var mp orb.MultiPolygon
loadJSON(b, "testdata/polygon.json", &mp)
text := MarshalString(mp[0])
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {
_, err := Unmarshal(text)
if err != nil {
b.Fatalf("unexpected error: %v", err)
}
}
}
func BenchmarkUnmarshalMultiPolygon_small(b *testing.B) {
mp := orb.MultiPolygon{{{{1, 2}, {3, 4}}}, {{{5, 6}, {7, 8}}, {{1, 2}, {5, 4}}}}
text := MarshalString(mp)
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {
_, err := Unmarshal(text)
if err != nil {
b.Fatalf("unexpected error: %v", err)
}
}
}
func BenchmarkUnmarshalMultiPolygon(b *testing.B) {
var mp orb.MultiPolygon
loadJSON(b, "testdata/polygon.json", &mp)
text := MarshalString(mp)
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {
_, err := Unmarshal(text)
if err != nil {
b.Fatalf("unexpected error: %v", err)
}
}
}
func loadJSON(tb testing.TB, filename string, obj interface{}) {
data, err := ioutil.ReadFile(filename)
if err != nil {
tb.Fatalf("failed to load mvt file: %v", err)
}
err = json.Unmarshal(data, obj)
if err != nil {
tb.Fatalf("unmarshal error: %v", err)
}
}