From e66cbd5b848587e5492070133cd964d989f0f248 Mon Sep 17 00:00:00 2001 From: PatrickWMartin Date: Fri, 22 Nov 2024 10:10:28 -0400 Subject: [PATCH] Add note on potential go benchmark optimisations (#781) * 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 --- iteration.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/iteration.md b/iteration.md index 28fc0313d..c2dc8b7aa 100644 --- a/iteration.md +++ b/iteration.md @@ -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