Created
February 2, 2017 13:27
-
-
Save awalterschulze/1b3f421dd3c71bad2e9a135d8216b2a4 to your computer and use it in GitHub Desktop.
golang: How to check whether a function is inlined
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import "fmt" | |
func main() { | |
x := 40 | |
y := 2 | |
res1 := inlinedFunc(x, y) | |
fmt.Println(res1) | |
res2 := notinlinedFunc(x, y) | |
fmt.Println(res2) | |
} | |
func inlinedFunc(x int, y int) int { | |
return x + y | |
} | |
func notinlinedFunc(x int, y int) int { | |
for i := 0; i < x; i++ { | |
x += y | |
} | |
return x | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
all: | |
make build | |
make objdump | |
build: | |
go build -gcflags -m main.go | |
objdump: | |
go tool objdump -s "main.main" main | grep CALL |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks to this post https://medium.com/@felipedutratine/does-golang-inline-functions-b41ee2d743fa#.3ubu50f06