Skip to content

Instantly share code, notes, and snippets.

@yu81
Created July 15, 2017 15:33
Show Gist options
  • Save yu81/2bdc50813d7093b3867a9d690daa669c to your computer and use it in GitHub Desktop.
Save yu81/2bdc50813d7093b3867a9d690daa669c to your computer and use it in GitHub Desktop.
// go 1.7.4 以下のベンチマークコードで go test -v -bench -benchmem を実行
func BenchmarkMatchFooBarBaz(b *testing.B) {
r := regexp.MustCompile("^foo")
const input = "foo"
b.ResetTimer()
for i := 0; i < b.N; i++ {
r.MatchString(input)
}
}
// -> BenchmarkMatchFoo-4 10000000 230 ns/op 0 B/op 0 allocs/op
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment