forked from kayon/iploc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
iploc_test.go
66 lines (58 loc) · 1.16 KB
/
iploc_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
package iploc
import (
"math/rand"
"testing"
"time"
)
const DATPath = "qqwry.dat"
func TestFind(t *testing.T) {
loc, err := Open(DATPath)
if err != nil {
t.Fatal(err)
}
detail1 := loc.Find("4.4")
detail2, _ := Find(DATPath, "4.0.0.4")
if detail1.Start.Compare(detail2.Start) != 0 || detail1.End.Compare(detail2.End) != 0 || detail1.String() != detail2.String() {
t.Fatal("error")
}
}
func BenchmarkFind(b *testing.B) {
b.StopTimer()
loc, err := Open(DATPath)
if err != nil {
b.Fatal(err)
}
rand.Seed(time.Now().UnixNano())
b.StartTimer()
for i := 0; i < b.N; i++ {
loc.FindUint(rand.Uint32())
}
}
func BenchmarkFindUnIndexed(b *testing.B) {
b.StopTimer()
loc, err := OpenWithoutIndexes(DATPath)
if err != nil {
b.Fatal(err)
}
rand.Seed(time.Now().UnixNano())
b.StartTimer()
for i := 0; i < b.N; i++ {
loc.FindUint(rand.Uint32())
}
}
func BenchmarkFindParallel(b *testing.B) {
b.StopTimer()
loc, err := Open(DATPath)
if err != nil {
b.Fatal(err)
}
rand.Seed(time.Now().UnixNano())
b.StartTimer()
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
if loc.FindUint(rand.Uint32()) == nil {
b.Fatal("error")
}
}
})
}