gpt4 book ai didi

testing - 你如何使用 go (golang) gocheck 测试框架的基准标志?

转载 作者:IT王子 更新时间:2023-10-29 01:09:41 36 4
gpt4 key购买 nike

如何使用 gocheck 的标志选项进行基准测试?测试框架?在我提供的链接中,他们提供的唯一示例似乎是运行 go test -check.b,但是,他们没有提供有关它如何工作的额外评论,因此很难使用它。当我执行 go help testgo help testflag 时,我什至无法在 go 文档中找到 -check。特别是我想知道如何更好地使用基准测试框架并控制它运行多长时间或运行多少次迭代等。例如在他们提供的示例中:

func (s *MySuite) BenchmarkLogic(c *C) { 
for i := 0; i < c.N; i++ {
// Logic to benchmark
}
}

有变量c.N。如何指定该变量?是通过实际程序本身还是通过 go test 及其标志或命令行?

旁注,go help testflag 的文档确实谈到了-bench regexbenchmembenchtime t 选项,但是,它没有讨论 -check.b 选项。然而,我确实尝试按照那里的描述运行这些选项,但它并没有真正做任何我能注意到的事情。 gocheck 是否适用于 go test 的原始选项?

我看到的主要问题是没有关于如何使用 gocheck 工具或其命令的明确文档。我不小心给了它一个错误的标志,它向我抛出一条错误消息,提示我需要的有用命令(描述有限):

  -check.b=false: Run benchmarks
-check.btime=1s: approximate run time for each benchmark
-check.f="": Regular expression selecting which tests and/or suites to run
-check.list=false: List the names of all tests that will be run
-check.v=false: Verbose mode
-check.vv=false: Super verbose mode (disables output caching)
-check.work=false: Display and do not remove the test working directory
-gocheck.b=false: Run benchmarks
-gocheck.btime=1s: approximate run time for each benchmark
-gocheck.f="": Regular expression selecting which tests and/or suites to run
-gocheck.list=false: List the names of all tests that will be run
-gocheck.v=false: Verbose mode
-gocheck.vv=false: Super verbose mode (disables output caching)
-gocheck.work=false: Display and do not remove the test working directory
-test.bench="": regular expression to select benchmarks to run
-test.benchmem=false: print memory allocations for benchmarks
-test.benchtime=1s: approximate run time for each benchmark
-test.blockprofile="": write a goroutine blocking profile to the named file after execution
-test.blockprofilerate=1: if >= 0, calls runtime.SetBlockProfileRate()
-test.coverprofile="": write a coverage profile to the named file after execution
-test.cpu="": comma-separated list of number of CPUs to use for each test
-test.cpuprofile="": write a cpu profile to the named file during execution
-test.memprofile="": write a memory profile to the named file after execution
-test.memprofilerate=0: if >=0, sets runtime.MemProfileRate
-test.outputdir="": directory in which to write profiles
-test.parallel=1: maximum test parallelism
-test.run="": regular expression to select tests and examples to run
-test.short=false: run smaller test suite to save time
-test.timeout=0: if positive, sets an aggregate time limit for all tests
-test.v=false: verbose: print additional output

编写错误的命令是获得此工具帮助的唯一途径吗?它没有帮助标志或其他东西吗?

最佳答案

我迟到了5年,但要指定运行多少N次。使用选项 -benchtime Nx

示例:

go test -bench=. -benchtime 100x

BenchmarkTest 100 ... ns/op

请阅读有关所有 go 测试标志的更多信息 here .

关于testing - 你如何使用 go (golang) gocheck 测试框架的基准标志?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24421535/

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