如何使用gocheck测试框架的标志选项进行基准测试?在我提供的链接中,似乎唯一提供的示例是通过运行
go test -check.b
来完成的,但是,他们并没有提供有关其工作原理的其他注释,因此很难使用它。 当我执行go help test
或go help testflag
时,我甚至找不到-check在go文档中的说明。特别是我想了解如何更好地使用基准测试框架,并控制其运行时间或迭代次数等等。例如,在他们提供的示例中:func (s *MySuite) BenchmarkLogic(c *C) {
for i := 0; i < c.N; i++ {
// Logic to benchmark
}
}
有一个变量c.N。如何指定该变量?是通过程序本身还是通过go test及其标志或命令行来指定的?
另外,来自go help testflag
的文档确实谈到了-bench regex
、benchmem
和benchtime 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
写错误命令是获取此工具帮助的唯一方式吗?它没有帮助标志或其他东西吗?
go test -check.b=.
修改为go test --check.b
或go test --gocheck.b
。 - hoenir