-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathbenchmark_test.go
54 lines (45 loc) · 992 Bytes
/
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
package checker
import "testing"
func BenchmarkIp(b *testing.B) {
type Test struct {
IP string
}
test := Test{IP: "127.0.0.1"}
ipChecker := NewChecker()
ipChecker.Add(Ip("IP"), "wrong ip")
b.ResetTimer()
for n := 0; n < b.N; n++ {
_, _, _ = ipChecker.Check(test)
}
}
func BenchmarkNot(b *testing.B) {
type Test struct {
NotIP string
}
test := Test{NotIP: "127.0.0.1.1"}
notIPChecker := NewChecker()
notIPChecker.Add(Not(Ip("IP")), "wrong ip")
b.ResetTimer()
for n := 0; n < b.N; n++ {
_, _, _ = notIPChecker.Check(test)
}
}
func BenchmarkMap(b *testing.B) {
kvMap := make(map[keyStruct]valueStruct)
keys := []keyStruct{{1}, {2}, {3}}
for _, key := range keys {
kvMap[key] = valueStruct{Value: 9}
}
m := mapStruct{
kvMap,
}
mapChecker := NewChecker()
mapRule := Map("Map",
RangeInt("Key", 1, 10),
InInt("Value", 8, 9, 10))
mapChecker.Add(mapRule, "invalid map")
b.ResetTimer()
for n := 0; n < b.N; n++ {
_, _, _ = mapChecker.Check(m)
}
}