Skip to content

Commit

Permalink
Add note on potential go benchmark optimisations (#781)
Browse files Browse the repository at this point in the history
* Fix style of note on benchmarks running in sequence

Note was italicized and didn't have a colon. This didn't match the other case of a note
in the itegers chaper which was.

* Add a note on go optimizing benchmarks

Added a note on go optimizing benchmarks and a link to Dave Cheney's blog post
on how to write benchmarks for how to make sure it doesn't. This optimization seems
rare from reading issues online but does happen so warning would be good to let people know.

* Fix wording to give a better sense of what go can do to optimize

* Fix missing period
  • Loading branch information
PatrickWMartin authored Nov 22, 2024
1 parent b6fe573 commit e66cbd5
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion iteration.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,9 @@ PASS

What `136 ns/op` means is our function takes on average 136 nanoseconds to run \(on my computer\). Which is pretty ok! To test this it ran it 10000000 times.

_NOTE_ by default Benchmarks are run sequentially.
**Note:** By default benchmarks are run sequentially.

**Note:** Sometimes, Go can optimize your benchmarks in a way that makes them inaccurate, such as eliminating the function being benchmarked. Check your benchmarks to see if the values make sense. If they seem overly optimized, you can follow the strategies in this **[blog post](https://dave.cheney.net/2013/06/30/how-to-write-benchmarks-in-go)**.

## Practice exercises

Expand Down

0 comments on commit e66cbd5

Please sign in to comment.