Compiling times

xuanbao · · 566 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>Hey. I recently started looking at Go and I am just writing a couple of small programs to get the hang of it.</p> <p>I just wanted to make sure that I am not compiling my Go apps in an inefficient or stupid way.</p> <p>Once I figure out which packages I want to import and work with I run the &#34;go install&#34; command. This takes 1-2 seconds. After that I run &#34;go build&#34; which takes 1-2 seconds as well. Is this considered fast? I am on a i7 4600u 2.1GHz CPU with 8 GB of RAM.</p> <p>Is this the right way to do it or is there a way to make the programs compile faster/safer?</p> <hr/>**评论:**<br/><br/>dbud: <pre><p>&#34;go install&#34; actually installs your app to $GOPATH/bin</p> <p>so, you don&#39;t really have any need of doing &#34;go build&#34;.</p> <p>Usually, I put $GOPATH/bin in my path and my &#34;dev cycle&#34; is.</p> <p>go install ./... &amp;&amp; app # where app is name of my binary.</p> <p>then a bounce is just Ctrl-C + Up + enter which gives me (usually) a 1 second cycle time to test changes</p></pre>DeedleFake: <pre><blockquote> <p>&#34;go install&#34; actually installs your app to $GOPATH/bin </p> </blockquote> <p>Or <code>$GOPATH/pkg</code> if it&#39;s not <code>main</code>.</p></pre>giovannibajo: <pre><p>You can use &#34;go build -v&#34; to see which packages are being compiled and &#34;-x&#34; to see actual process calls in case you want to dive further.</p> <p>The important part is to understand that &#34;go build&#34; doesn&#39;t cache compilation of packages, it just creates the final file and throw all intermediate files. So if your program is made by 3 packages, &#34;go build&#34; will normally recompile all three of them.</p> <p>You can use &#34;go build -i&#34; to force Go to create .a files for dependent packages (stored in $GOPATH/pkg), so that you don&#39;t need to compile them over and over. I run &#34;go build -i&#34; as my standard build command.</p></pre>afghanPower: <pre><p>Ran &#34;go build -i&#34; on one of my &#34;gin-gonic&#34; test programs. It doesn&#39;t seem to make the compiling faster. Which is kind of weird, isn&#39;t it? You would think that not compiling these dependent packages would make the compiling faster:</p> <pre><code> import ( &#34;database/sql&#34; &#34;log&#34; &#34;strconv&#34; &#34;time&#34; &#34;github.com/coopernurse/gorp&#34; &#34;github.com/gin-gonic/gin&#34; _ &#34;github.com/mattn/go-sqlite3&#34; </code></pre> <p>)</p></pre>dlsniper: <pre><p>Use go install on the go-sqlite3 package and hopefully that should improve the compile times.</p></pre>afghanPower: <pre><p>Have run the &#34;go install #pkg_link&#34; on all of the github packages.</p></pre>dlsniper: <pre><p>Oh, I see. You are importing the package_ Try to separate that logic into a separate package and then go install that package. Overall compile times should improve at the cost of having to install that package when you change it </p></pre>robertmeta: <pre><p>Why not just <strong>go install</strong>? </p> <p>Isn&#39;t <strong>go build</strong> considered bad practice at this point? </p></pre>TheMerovius: <pre><p>Use <code>go build -v -i</code>, whenever something&#39;s slow. You&#39;ll figure out what is slow and it will probably not continue to be slow.</p></pre>lhxtx: <pre><p>No need to run go build after go install. Go build just builds the binary in the packages directory. Go install builds the binary and puts it in $GOPATH/bin (which would be on your system&#39;s path, so you can call it anywhere)</p></pre>

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

566 次点击  
加入收藏 微博
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传