question: How to run benchmarks on the standard library ?

agolangf · · 59 次点击    
<p>I have been optimizing the fmt package and would like to run benchmarks and do some comparison. However, I am having a hard time trying to get the benchmarks to run.</p> <p>I can run tests with the <code>./all.bash</code>. Or even if I do <code>go tool dist test</code>. I am able to somehow trigger the benchmarks with <code>go tool dist test -run=fmt -race</code> - it says &#34;running benchmarks briefly&#34;. But I would like to run the full &#34;benchmem&#34; option too.</p> <p>I am a beginner go contributor, so I apologize if this is a stupid question.</p> <p>Any help is appreciated :)</p> <hr/>**评论:**<br/><br/>joetsai: <pre><p>It&#39;s not a stupid question, it was something I struggled with initially too when I first started contributing.</p> <p>Let&#39;s suppose you have the go source checked out in:</p> <pre><code>/home/rawr/Projects/go </code></pre> <p>Let&#39;s build the toolchain first:</p> <pre><code>(cd /home/rawr/Projects/go/src &amp;&amp; ./make.bash) </code></pre> <p>Then we can use the toolchain we just build to run tests:</p> <pre><code>/home/rawr/Projects/go/bin/go test fmt -bench =. </code></pre> <p>This assumes that your GOROOT is not explicitly set. Otherwise, you can explicitly set it before running:</p> <pre><code>GOROOT=/home/rawr/Projects/go /home/rawr/Projects/go/bin/go ... </code></pre></pre>itachi_amaterasu: <pre><p>Ahh .. right. You have to use the toolchain go. Thanks ! makes total sense. </p></pre>0xjnml: <pre><pre><code>$ cd $(go env GOROO)/src/fmt $ go test -bench . -benchmem | tee ~/old $ git checkout -b mybranch ... $ go test -bench . -benchmem | tee ~/new $ benchcmp -mag -changed ~/old ~/new </code></pre></pre>
59 次点击  
加入收藏 微博
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传