gpt4 book ai didi

从 main/go Playground 运行 Go 基准测试

转载 作者:IT王子 更新时间:2023-10-29 01:25:42 26 4
gpt4 key购买 nike

我正在尝试创建一套基准测试

https://play.golang.org/p/uWWITU-WKaL

主要包

import (
"fmt"
"testing"
)

func runall(a, b string) (bool, error) {
return true, nil
}

func main() {
bench := []testing.InternalBenchmark{
{
F: Benchmark_Dev,
},
}

tests := []testing.InternalTest{
{
F: Test_Dev,
},
}
testing.Main(runall, tests, bench, nil)
}

func Test_Dev(t *testing.T) {
fmt.Println("Test_Dev")
}

func Benchmark_Dev(b *testing.B) {
fmt.Println("Benchmark_Dev")
b.ReportAllocs()
for i := 0; i < b.N; i++ {
res := i % 10
fmt.Println(res)
}
}

我看到测试运行良好,但基准测试从未运行过。

最佳答案

如果您阅读 "About" on Go Playground :

If the program contains tests or examples and no main function, the service runs the tests. Benchmarks will likely not be supported since the program runs in a sandboxed environment with limited resources.

你会找到你的答案

关于从 main/go Playground 运行 Go 基准测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54574814/

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