<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 "running benchmarks briefly". But I would like to run the full "benchmem" 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's not a stupid question, it was something I struggled with initially too when I first started contributing.</p>
<p>Let's suppose you have the go source checked out in:</p>
<pre><code>/home/rawr/Projects/go
</code></pre>
<p>Let's build the toolchain first:</p>
<pre><code>(cd /home/rawr/Projects/go/src && ./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>
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889
- 请尽量让自己的回复能够对别人有帮助
- 支持 Markdown 格式, **粗体**、~~删除线~~、
`单行代码`
- 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
- 图片支持拖拽、截图粘贴等方式上传