Skip to content

Instantly share code, notes, and snippets.

@blanchonvincent
Last active September 6, 2019 17:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save blanchonvincent/d4ed01d31b3ed99eb5cd87629ecfe926 to your computer and use it in GitHub Desktop.
Save blanchonvincent/d4ed01d31b3ed99eb5cd87629ecfe926 to your computer and use it in GitHub Desktop.
Medium - Instrumentation statements
package main
import "math/rand"
func main() {
println(run())
}
//go:noinline
func run() int {
a := 0
for i:= 0; i < rand.Intn(100000); i++ {
if i % 2 == 0 {
add(&a)
} else {
sub(&a)
}
}
return a
}
//go:noinline
func add(a *int) {
*a += rand.Intn(10)
}
//go:noinline
func sub(a *int) {
*a -= rand.Intn(10)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment