-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* optimize code * update README_zh.md * update travis * update travis * fix travis * update README
- Loading branch information
1 parent
5dcf01f
commit 43b4ba1
Showing
20 changed files
with
695 additions
and
439 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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) | ||
} | ||
} |
Oops, something went wrong.