-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwurfl_test.go
98 lines (84 loc) · 2.11 KB
/
wurfl_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
package wurfl
import (
"math/rand"
"os"
"path/filepath"
"runtime"
"testing"
)
// Old library test 30s
// goos: linux
// goarch: amd64
// pkg: informer/wurfl
// Benchmark_Lookup-2 500000 98068 ns/op 1084 B/op 23 allocs/op
// PASS
// ok informer/wurfl 68.372s
// New library test 30s
// goos: linux
// goarch: amd64
// pkg: informer/lib/wurfl
// Benchmark_Lookup-2 300000 123769 ns/op 18418 B/op 491 allocs/op
// Benchmark_LookupProperties-2 2000000 27232 ns/op 1248 B/op 13 allocs/op
// PASS
// ok informer/lib/wurfl 133.134s
//
// Benchmark_LookupProperties-2 equal to Benchmark_Lookup-2
var (
props = []string{
"mobile_browser",
"is_tablet",
}
vprops = []string{
"form_factor",
"advertised_browser",
"advertised_device_os",
"advertised_device_os_version",
"is_robot",
"is_full_desktop",
"is_mobile",
}
)
func Benchmark_Lookup(b *testing.B) {
_, file, _, _ := runtime.Caller(0)
absfilepath := filepath.Join(filepath.Dir(file), "wurfl.xml.gz")
if _, err := os.Stat(absfilepath); os.IsNotExist(err) {
b.Skip("wurfl.xml.gz is not available. We can`t place commercial DB in the public repository")
}
wrfl, err := New(absfilepath)
defer wrfl.Close()
if err != nil {
b.Error(err)
return
}
b.ResetTimer()
b.ReportAllocs()
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
agent := agentsList[rand.Int31n(int32(len(agentsList)))]
device := wrfl.Lookup(agent)
device.Release()
}
})
}
func Benchmark_LookupProperties(b *testing.B) {
_, file, _, _ := runtime.Caller(0)
absfilepath := filepath.Join(filepath.Dir(file), "wurfl.xml.gz")
if _, err := os.Stat(absfilepath); os.IsNotExist(err) {
b.Skip("wurfl.xml.gz is not available. We can`t place commercial DB in the public repository")
}
wrfl, err := New(absfilepath)
defer wrfl.Close()
if err != nil {
b.Error(err)
return
}
b.ResetTimer()
b.ReportAllocs()
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
agent := agentsList[rand.Int31n(int32(len(agentsList)))]
device := wrfl.LookupProperties(agent, props, vprops)
device.Release()
}
})
}