Why my "go test" running so slow?

polaris · · 718 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>every time I made a modification, go test takes a long time to run. I only run a single test, like, go test pkg/ds/ds... -run TestCase1 -v</p> <hr/>**评论:**<br/><br/>silenceofnight: <pre><p>It rebuilds the related binary every time.</p> <p>You can make subsequent test runs faster by first running <code>go test -i ./pkg/blah/...</code> before running <code>go test ./pkg/blah/...</code></p></pre>losinggeneration: <pre><p>To elaborate a bit more, it&#39;s having to build the binary and all dependences. Pure Go packages are pretty quick to compile, but lots of dependencies can take a bit of time to find on disk and compile. If any of the code has any C or C++ to compile, the compile time goes up significantly (sqlite for example.) </p> <p>e: If the packages are installed, as mentioned with go test -i, it doesn&#39;t have to recompile the dependencies (unless their source has changed.)</p></pre>marksteve4: <pre><p>this is just the same slow if not slower. How about -c?</p></pre>jerf: <pre><p><code>-c</code> would skip the step where it runs the test and you&#39;d have to run it yourself. While this might, ironically, make it feel faster, it would not actually be faster.</p> <p>If it isn&#39;t being fixed by <code>go test -i</code>, which was my first thought as well, the next thing to try is running <code>go test -v</code> and just watching the output. If the first output <code>=== RUN (your test name)</code> comes out quickly, then the compile is happening quickly enough; you may have a slow test.</p> <p>If that still isn&#39;t fast, and if you are not compiling an excessive amount of code in your package or linking to an excessive number of packages (lots and lots of &#34;import&#34; packages, like, many dozens), the next thing I would be looking at is the system itself; are you in swap? Is something eating 100% of your CPU that you didn&#39;t know about? Have a look at your hard drive&#39;s SMART statistics, too. I have had hard drives that &#34;work&#34; but are actually throwing errors every which way, in which case you need to stop working on your Go program and start getting everything off the drive. (Long shot in terms of fixing this problem, but worth mentioning due to the high potential impact.)</p> <p>Failing all that, I think we&#39;d need to see the test code in question, if at all possible. Right now, with all due respect, your report is basically &#34;It&#39;s slow. Why?&#34; There&#39;s not a lot to grab on to, there; we barely even have a hint what &#34;it&#34; is. <a href="http://www.catb.org/esr/faqs/smart-questions.html" rel="nofollow">You may find this helpful</a>.</p></pre>marksteve4: <pre><p>This is a great answer. Thanks</p></pre>j_d_q: <pre><p>I&#39;d also throw in <code>-x</code> to see what it&#39;s doing before it runs</p></pre>

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

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