Skip to content

Commit

Permalink
bytes: add benchmark for LastIndex
Browse files Browse the repository at this point in the history
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 <[email protected]>
TryBot-Result: Gobot Gobot <[email protected]>
Reviewed-by: Ian Lance Taylor <[email protected]>
  • Loading branch information
tklauser committed Mar 8, 2019
1 parent 3f3d604 commit b4baa8d
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/bytes/bytes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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("</pre>")) }
func BenchmarkLastIndexHard3(b *testing.B) { benchmarkLastIndexHard(b, []byte("<b>hello world</b>")) }

func BenchmarkSplitEmptySeparator(b *testing.B) {
for i := 0; i < b.N; i++ {
Split(benchInputHard, nil)
Expand Down

0 comments on commit b4baa8d

Please sign in to comment.