Passing an optimization flag to a Go compiler?

我与影子孤独终老i 提交于 2021-02-07 11:33:03

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!