From: Tobias Klauser Date: Fri, 8 Mar 2019 10:36:31 +0000 (+0100) Subject: bytes: add benchmark for LastIndex X-Git-Tag: go1.13beta1~1142 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=b4baa8dd1d8bc1d65e80e88c294729554bab72b8;p=gostls13.git bytes: add benchmark for LastIndex Add BenchmarkLastIndexHard[1-3] in preparation for implementing LastIndex using Rabin-Karp akin to strings.LastIndex BenchmarkLastIndexHard1-8 500 3162694 ns/op BenchmarkLastIndexHard2-8 500 3170475 ns/op BenchmarkLastIndexHard3-8 500 3051127 ns/op Change-Id: Id99f85f9640e248958f2b4be4dfd8c974e3b50e7 Reviewed-on: https://go-review.googlesource.com/c/go/+/166257 Run-TryBot: Tobias Klauser TryBot-Result: Gobot Gobot Reviewed-by: Ian Lance Taylor --- diff --git a/src/bytes/bytes_test.go b/src/bytes/bytes_test.go index f4c0ffd2a9..80a54f6118 100644 --- a/src/bytes/bytes_test.go +++ b/src/bytes/bytes_test.go @@ -1642,6 +1642,16 @@ func makeBenchInputHard() []byte { var benchInputHard = makeBenchInputHard() +func benchmarkLastIndexHard(b *testing.B, sep []byte) { + for i := 0; i < b.N; i++ { + LastIndex(benchInputHard, sep) + } +} + +func BenchmarkLastIndexHard1(b *testing.B) { benchmarkLastIndexHard(b, []byte("<>")) } +func BenchmarkLastIndexHard2(b *testing.B) { benchmarkLastIndexHard(b, []byte("")) } +func BenchmarkLastIndexHard3(b *testing.B) { benchmarkLastIndexHard(b, []byte("hello world")) } + func BenchmarkSplitEmptySeparator(b *testing.B) { for i := 0; i < b.N; i++ { Split(benchInputHard, nil)