forked from paulmach/osm
-
Notifications
You must be signed in to change notification settings - Fork 2
/
benchmarks_test.go
105 lines (85 loc) · 1.86 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
package osmgeojson
import (
"encoding/xml"
"io/ioutil"
"testing"
"github.com/onXmaps/osm"
)
func BenchmarkConvert(b *testing.B) {
o := parseFile(b, "testdata/benchmark.osm")
b.ReportAllocs()
b.ResetTimer()
for n := 0; n < b.N; n++ {
Convert(o)
}
}
func BenchmarkConvertAnnotated(b *testing.B) {
o := parseFile(b, "testdata/benchmark.osm")
annotate(o)
b.ReportAllocs()
b.ResetTimer()
for n := 0; n < b.N; n++ {
Convert(o)
}
}
func BenchmarkConvert_NoID(b *testing.B) {
o := parseFile(b, "testdata/benchmark.osm")
b.ReportAllocs()
b.ResetTimer()
for n := 0; n < b.N; n++ {
Convert(o, NoID(true))
}
}
func BenchmarkConvert_NoMeta(b *testing.B) {
o := parseFile(b, "testdata/benchmark.osm")
b.ReportAllocs()
b.ResetTimer()
for n := 0; n < b.N; n++ {
Convert(o, NoMeta(true))
}
}
func BenchmarkConvert_NoRelationMembership(b *testing.B) {
o := parseFile(b, "testdata/benchmark.osm")
b.ReportAllocs()
b.ResetTimer()
for n := 0; n < b.N; n++ {
Convert(o, NoRelationMembership(true))
}
}
func BenchmarkConvert_NoIDsMetaMembership(b *testing.B) {
o := parseFile(b, "testdata/benchmark.osm")
b.ReportAllocs()
b.ResetTimer()
for n := 0; n < b.N; n++ {
Convert(o, NoID(true), NoMeta(true), NoRelationMembership(true))
}
}
func parseFile(t testing.TB, filename string) *osm.OSM {
data, err := ioutil.ReadFile(filename)
if err != nil {
t.Fatalf("could not read file: %v", err)
}
o := &osm.OSM{}
err = xml.Unmarshal(data, &o)
if err != nil {
t.Fatalf("failed to unmarshal %s: %v", filename, err)
}
return o
}
func annotate(o *osm.OSM) {
nodes := make(map[osm.NodeID]*osm.Node)
for _, n := range o.Nodes {
nodes[n.ID] = n
}
for _, w := range o.Ways {
for i, wn := range w.Nodes {
n := nodes[wn.ID]
if n == nil {
continue
}
w.Nodes[i].Lat = n.Lat
w.Nodes[i].Lon = n.Lon
w.Nodes[i].Version = n.Version
}
}
}