Last active
October 20, 2017 09:37
-
-
Save yoppi/325bf2f849f5fb25b127f84b402ab43f to your computer and use it in GitHub Desktop.
キャプチャするしない
This file contains hidden or 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
package regexp | |
import ( | |
"regexp" | |
"testing" | |
) | |
func BenchmarkRegexp1(b *testing.B) { | |
re := regexp.MustCompile(`(iTunes)/(\d+)\.(\d+)`) | |
for i := 0; i < b.N; i++ { | |
re.MatchString("iTunes/12.7 (Macintosh; OS X 10.11.6) AppleWebKit/601.7.8") | |
re.MatchString("Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en-US) AppleWebKit/533.3 (KHTML, like Gecko) cXensebot/1.1a; +http://www.cxense.com/bot.html/0.1 Safari/533.3") | |
} | |
} | |
func BenchmarkRegexp2(b *testing.B) { | |
re := regexp.MustCompile(`iTunes/\d+\.\d+`) | |
for i := 0; i < b.N; i++ { | |
re.MatchString("iTunes/12.7 (Macintosh; OS X 10.11.6) AppleWebKit/601.7.8") | |
re.MatchString("Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en-US) AppleWebKit/533.3 (KHTML, like Gecko) cXensebot/1.1a; +http://www.cxense.com/bot.html/0.1 Safari/533.3") | |
} | |
} |
This file contains hidden or 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
$ go test -bench=. -benchmem [~/src/github.com/yoppi/go/regexp] | |
goos: darwin | |
goarch: amd64 | |
pkg: github.com/yoppi/go/regexp | |
BenchmarkRegexp1-4 3000000 774 ns/op 0 B/op 0 allocs/op | |
BenchmarkRegexp3-4 3000000 521 ns/op 0 B/op 0 allocs/op | |
PASS | |
ok github.com/yoppi/go/regexp 4.922s |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment