forked from hdczsf/51degrees.go
-
Notifications
You must be signed in to change notification settings - Fork 3
/
parse_test.go
52 lines (40 loc) · 1.14 KB
/
parse_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
package fiftyonedegrees
import (
"testing"
)
func TestProviderParse(t *testing.T) {
userAgentDB, err := mustLoadProviderData(2, 1000)
if err != nil {
t.Fatal("could not load DB: %s", err)
}
testUA := "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.124 Safari/537.36"
userAgentDB.Parse(testUA)
userAgentDB.Close()
}
/*
* Benchmarking code starts here
*/
func BenchmarkProviderParse(b *testing.B) {
userAgentDB, err := mustLoadProviderData(2, 1000)
if err != nil {
b.Fatal("could not load DB: %s", err)
}
defer userAgentDB.Close()
testUA := "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.124 Safari/537.36"
b.ResetTimer()
for i := 0; i < b.N; i++ {
userAgentDB.Parse(testUA)
}
}
func BenchmarkDataSetParse(b *testing.B) {
userAgentDB, err := mustLoadDataSet()
if err != nil {
b.Fatal("could not load DB: %s", err)
}
defer userAgentDB.Close()
testUA := "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.124 Safari/537.36"
b.ResetTimer()
for i := 0; i < b.N; i++ {
userAgentDB.Parse(testUA)
}
}