-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathxmlbench_test.go
More file actions
46 lines (43 loc) · 915 Bytes
/
xmlbench_test.go
File metadata and controls
46 lines (43 loc) · 915 Bytes
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
package xmlbench
import (
"testing"
"xmlbench/file"
)
func BenchmarkParsers(b *testing.B) {
benchmarks := []struct {
xmlFilePath string
}{
// {"hotels.xml"},
// {"flights.xml"},
{"exampleResponse.xml"},
}
for _, bm := range benchmarks {
// Read file contents
fileContents, err := file.GetFileContents(bm.xmlFilePath)
if err != nil {
b.Fatal(err)
}
b.Run(bm.xmlFilePath+"-encoding/xml", func(b *testing.B) {
for i := 0; i < b.N; i++ {
if err := Parser1(fileContents); err != nil {
b.Fatal(err)
}
// os.Exit(0)
}
})
b.Run(bm.xmlFilePath+"-cvik/xml", func(b *testing.B) {
for i := 0; i < b.N; i++ {
if err := Parser2(fileContents); err != nil {
b.Fatal(err)
}
}
})
b.Run(bm.xmlFilePath+"-libxml2", func(b *testing.B) {
for i := 0; i < b.N; i++ {
if err := Parser3(fileContents); err != nil {
b.Fatal(err)
}
}
})
}
}