Skip to content

Instantly share code, notes, and snippets.

@awalterschulze
Created February 2, 2017 13:27
Show Gist options
  • Save awalterschulze/1b3f421dd3c71bad2e9a135d8216b2a4 to your computer and use it in GitHub Desktop.
Save awalterschulze/1b3f421dd3c71bad2e9a135d8216b2a4 to your computer and use it in GitHub Desktop.
golang: How to check whether a function is inlined
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
}
all:
make build
make objdump
build:
go build -gcflags -m main.go
objdump:
go tool objdump -s "main.main" main | grep CALL
@awalterschulze
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment