我想为golang做一点贡献,并需要运行基准测试,例如编码/json。
我的所有尝试都失败(go1.13):
❯ go test -bench encoding/json
build .: cannot find module for path .
❯ go test encoding/json
ok encoding/json 1.412s
❯ go test -bench std/encoding/json
build .: cannot find module for path .
❯ go test std/encoding/json
# std/encoding/json
package std/encoding/json (test)
imports internal/testenv: use of internal package internal/testenv not allowed
FAIL std/encoding/json [setup failed]
FAIL
❯ go test std
ok archive/tar (cached)
❯ go test -bench std
build .: cannot find module for path .
那么我如何独占地测试编码/json呢?
发布于 2019-09-10 02:09:08
如果这是go源代码树的最新签出,则在引导(即运行all.bash)之后,转到go/src/下并运行
../bin/go test ./encoding/json -bench=.
或者,您也可以在/usr/local/go/src下以同样的方式对已安装的版本运行它。
如果您计划提交性能增强,他们会希望您进行之前/之后的基准测试比较。因此,在前后运行基准测试10-20次,并使用benchstat
工具比较结果。
../bin/go test ./encoding/json -bench=. -count=10 >after
发布于 2019-09-10 02:07:42
我相信这是由于Go模块造成的,但对我来说起作用的是从stdlib中执行:
cd /usr/local/go/src/encoding/json
go test -run='^$' -bench .
https://stackoverflow.com/questions/57859015
复制相似问题