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

testing: document best practices for avoiding compiler optimizations in benchmarks #27400

nicksnyder opened this Issue Aug 31, 2018 · 3 comments


None yet
6 participants
Copy link

nicksnyder commented Aug 31, 2018

What did you do?

  1. I wanted to make sure I was creating accurate benchmarks.
  2. I found and read Dave Cheney's 2013 blog post on how to write benchmarks in Go. In the "A note on compiler optimisations" section he mentions that it is best practice to assign results to local and package level variables to avoid optimizations.
  3. I went to

What did you expect to see?

I expected to see documentation on how to correctly write benchmarks that avoid compiler optimizations and examples that reflect best practices.

If the techniques described in Dave's blog post are no longer necessary, I expected to see explicit documentation to that effect.

What did you see instead?

Neither of those things.

@meirf meirf added help wanted and removed help wanted labels Aug 31, 2018


This comment has been minimized.

Copy link

meirf commented Aug 31, 2018


Is that kind of optimization avoidance still recommended?

If so, do you think that info should be put in I don't see an official benchmark wiki so seems useful to give a short explanation in testing doc.

@FiloSottile FiloSottile added this to the Unplanned milestone Aug 31, 2018


This comment has been minimized.

Copy link

as commented Sep 1, 2018

Couldn't reproduce benchmark code elision in currently-supported Go versions.


This comment has been minimized.

Copy link

josharian commented Sep 1, 2018

@as I believe it can happen now with inlined calls. There is discussion of purity analysis, which might impact non-inlined pure calls later.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.