-
Notifications
You must be signed in to change notification settings - Fork 0
/
benchmark_test.go
124 lines (105 loc) · 2.6 KB
/
benchmark_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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
package test
import (
"fmt"
"os"
"testing"
"github.com/ip2location/ip2location-go/v9"
"github.com/pg9182/ip2x"
)
func TestMain(m *testing.M) {
fmt.Printf("db: %s\n", IP2x_DB)
os.Exit(m.Run())
}
func BenchmarkIP2x_Init(b *testing.B) {
for i := 0; i < b.N; i++ {
ip2x.New(DB)
}
}
func BenchmarkIP2x_LookupOnly(b *testing.B) {
for i := 0; i < b.N; i++ {
IP2x_DB.Lookup(ips[i%len(ips)])
}
}
func BenchmarkIP2x_GetAll(b *testing.B) {
for i := 0; i < b.N; i++ {
r, _ := IP2x_DB.Lookup(ips[i%len(ips)])
IP2x_DB.EachField(func(d ip2x.DBField) bool {
r.Get(d)
return true
})
}
}
func BenchmarkIP2x_GetOneString(b *testing.B) {
for i := 0; i < b.N; i++ {
r, _ := IP2x_DB.Lookup(ips[i%len(ips)])
r.GetString(ip2x.CountryCode)
}
}
func BenchmarkIP2x_GetOneFloat(b *testing.B) {
for i := 0; i < b.N; i++ {
r, _ := IP2x_DB.Lookup(ips[i%len(ips)])
r.GetFloat32(ip2x.Latitude)
}
}
func BenchmarkIP2x_GetTwoString(b *testing.B) {
for i := 0; i < b.N; i++ {
r, _ := IP2x_DB.Lookup(ips[i%len(ips)])
r.GetString(ip2x.CountryCode)
r.GetString(ip2x.Region)
}
}
func BenchmarkIP2x_GetTwoFloat(b *testing.B) {
for i := 0; i < b.N; i++ {
r, _ := IP2x_DB.Lookup(ips[i%len(ips)])
r.GetFloat32(ip2x.Latitude)
r.GetFloat32(ip2x.Longitude)
}
}
func BenchmarkIP2x_GetNonexistent(b *testing.B) {
for i := 0; i < b.N; i++ {
r, _ := IP2x_DB.Lookup(ips[i%len(ips)])
r.GetString(ip2x.MCC)
}
}
func BenchmarkIP2LocationV9_Init(b *testing.B) {
for i := 0; i < b.N; i++ {
ip2location.OpenDBWithReader(DB)
}
}
func BenchmarkIP2LocationV9_LookupOnly(b *testing.B) {
for i := 0; i < b.N; i++ {
ip2locationv9_query(IP2LocationV9_DB, ipstrs[i%len(ips)], 0)
}
}
func BenchmarkIP2LocationV9_GetAll(b *testing.B) {
for i := 0; i < b.N; i++ {
IP2LocationV9_DB.Get_all(ipstrs[i%len(ips)])
}
}
func BenchmarkIP2LocationV9_GetOneString(b *testing.B) {
for i := 0; i < b.N; i++ {
IP2LocationV9_DB.Get_country_short(ipstrs[i%len(ips)])
}
}
func BenchmarkIP2LocationV9_GetOneFloat(b *testing.B) {
for i := 0; i < b.N; i++ {
IP2LocationV9_DB.Get_latitude(ipstrs[i%len(ips)])
}
}
func BenchmarkIP2LocationV9_GetTwoString(b *testing.B) {
for i := 0; i < b.N; i++ {
IP2LocationV9_DB.Get_country_short(ipstrs[i%len(ips)])
IP2LocationV9_DB.Get_country_long(ipstrs[i%len(ips)])
}
}
func BenchmarkIP2LocationV9_GetTwoFloat(b *testing.B) {
for i := 0; i < b.N; i++ {
IP2LocationV9_DB.Get_latitude(ipstrs[i%len(ips)])
IP2LocationV9_DB.Get_longitude(ipstrs[i%len(ips)])
}
}
func BenchmarkIP2LocationV9_GetNonexistent(b *testing.B) {
for i := 0; i < b.N; i++ {
IP2LocationV9_DB.Get_mcc(ipstrs[i%len(ips)])
}
}