gpt4 book ai didi

go - 如何对 golang 标准库的包进行基准测试?

转载 作者:行者123 更新时间:2023-12-02 18:30:29 25 4
gpt4 key购买 nike

我想为 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 .

那么我如何专门测试encoding/json?

最佳答案

如果这是 go 源代码树的全新 check out ,则在引导(即运行 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

关于go - 如何对 golang 标准库的包进行基准测试?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57859015/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com