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

Open
nicksnyder opened this Issue Aug 31, 2018 · 3 comments

Comments

Projects
None yet
6 participants
@nicksnyder

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 https://golang.org/pkg/testing/#hdr-Benchmarks

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

@meirf

This comment has been minimized.

Member

meirf commented Aug 31, 2018

@davecheney,

Is that kind of optimization avoidance still recommended?

If so, do you think that info should be put in https://golang.org/pkg/testing/#hdr-Benchmarks? 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

@as

This comment has been minimized.

Contributor

as commented Sep 1, 2018

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

@josharian

This comment has been minimized.

Contributor

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