]> Cypherpunks repositories - gostls13.git/commitdiff
strings: add IndexByte benchmark
authorBrad Fitzpatrick <bradfitz@golang.org>
Tue, 6 Aug 2013 21:41:07 +0000 (14:41 -0700)
committerBrad Fitzpatrick <bradfitz@golang.org>
Tue, 6 Aug 2013 21:41:07 +0000 (14:41 -0700)
Like existing Index, IndexRune, IndexHardN, etc.

R=golang-dev, khr
CC=golang-dev
https://golang.org/cl/12486044

src/pkg/strings/strings_test.go

index 68b658ca466612e423c3f598b317d8d1ae72af2f..5ffb4e208c92d17d8406162695a99208492d4470 100644 (file)
@@ -168,6 +168,15 @@ func BenchmarkIndex(b *testing.B) {
        }
 }
 
+func BenchmarkIndexByte(b *testing.B) {
+       if got := IndexByte(benchmarkString, 'v'); got != 17 {
+               b.Fatalf("wrong index: expected 17, got=%d", got)
+       }
+       for i := 0; i < b.N; i++ {
+               IndexByte(benchmarkString, 'v')
+       }
+}
+
 var explodetests = []struct {
        s string
        n int