From: Brad Fitzpatrick Date: Tue, 8 Mar 2011 17:58:18 +0000 (-0800) Subject: strings: better benchmark names; add BenchmarkIndex X-Git-Tag: weekly.2011-03-15~78 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=64f75f103408b5cfd94d1aacf400e7f9ce3fe58a;p=gostls13.git strings: better benchmark names; add BenchmarkIndex R=dsymonds CC=golang-dev https://golang.org/cl/4264052 --- diff --git a/src/pkg/strings/strings_test.go b/src/pkg/strings/strings_test.go index b218c7a2ab..41e398782e 100644 --- a/src/pkg/strings/strings_test.go +++ b/src/pkg/strings/strings_test.go @@ -138,24 +138,36 @@ func TestIndexRune(t *testing.T) { } } +const benchmarkString = "some_text=some☺value" + func BenchmarkIndexRune(b *testing.B) { - if got := IndexRune("some_text=some☺value", '☺'); got != 14 { + if got := IndexRune(benchmarkString, '☺'); got != 14 { + panic("wrong index: got=" + strconv.Itoa(got)) + } + for i := 0; i < b.N; i++ { + IndexRune(benchmarkString, '☺') + } +} + +func BenchmarkIndexRuneFastPath(b *testing.B) { + if got := IndexRune(benchmarkString, 'v'); got != 17 { panic("wrong index: got=" + strconv.Itoa(got)) } for i := 0; i < b.N; i++ { - IndexRune("some_text=some☺value", '☺') + IndexRune(benchmarkString, 'v') } } -func BenchmarkIndexByte(b *testing.B) { - if got := IndexRune("some_text=some☺value", 'v'); got != 17 { +func BenchmarkIndex(b *testing.B) { + if got := Index(benchmarkString, "v"); got != 17 { panic("wrong index: got=" + strconv.Itoa(got)) } for i := 0; i < b.N; i++ { - IndexRune("some_text=some☺value", 'v') + Index(benchmarkString, "v") } } + type ExplodeTest struct { s string n int