问题
To compile a Go program you type go build myprogram.go
, can you pass an optimization flags along or the code is always compiled in the same way? I am talking about speed optimizations, code size optimizations or other optimizations.
I know if you use gccgo
you just pass -O2
or -O0
but my question is about an official Go compiler go
.
回答1:
Actually no explicit flags, this Go wiki page lists optimizations done by the Go compiler and there was a discussion around this topic in golang-nuts groups.
You can turn off optimization and inlining in Go gc compilers for debugging.
-gcflags '-N -l'
-N
: Disable optimizations-l
: Disable inlining
来源:https://stackoverflow.com/questions/45003259/passing-an-optimization-flag-to-a-go-compiler