Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

runtime: indexbytebody runs slower on short strings than 16 byte strings on amd64 #13983

Closed
prashantv opened this issue Jan 16, 2016 · 2 comments
Milestone

Comments

@prashantv
Copy link
Contributor

While doing some benchmarking, I noticed that strings.IndexByte was slower than a simple index-based for loop. This was originally reported here:
https://groups.google.com/forum/#!topic/golang-nuts/Vjy_UUcugPE

Keith observed that the benchmark ran faster when the string length was increased to 16 characters.

For a < 16 character string, the results change dramatically:

BenchmarkGetHostIndexByte-8     100000000           23.3 ns/op
BenchmarkGetHostIndexLoop-8     200000000            9.92 ns/op

For a 16 character string, the benchmarks are:

BenchmarkGetHostIndexByte-8     200000000            5.91 ns/op
BenchmarkGetHostIndexLoop-8     200000000            9.17 ns/op

Keith mentioned that the REP instruction was most likely to blame.

@bradfitz bradfitz added this to the Go1.7 milestone Jan 16, 2016
@bradfitz
Copy link
Contributor

@gopherbot
Copy link

CL https://golang.org/cl/18703 mentions this issue.

@golang golang locked and limited conversation to collaborators Feb 28, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants