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

Pin*_*hio 9 testing benchmarking go

如何使用gocheck测试框架的基准测试标志选项?在我提供的链接中,似乎它们提供的唯一示例是通过运行go test -check.b,但是,它们不提供有关其工作原理的其他注释,因此很难使用它.在我做的go help test时候,当我做的时候,我甚至都找不到-check go help testflag.特别是我想知道如何更好地使用基准测试框架并控制它运行的时间或运行的迭代次数等等.例如,在他们提供的示例中:

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

有变量cN如何指定变量?是通过实际程序本身还是通过测试及其标志或命令行?

在侧面说明,从文档go help testflag没有谈 -bench regex,benchmembenchtime 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
Run Code Online (Sandbox Code Playgroud)

写错了命令是获得这个工具帮助的唯一方法吗?它没有帮助标志或什么?

Ous*_*bel 12

我迟到了5年,不过要指定跑多少N次。使用选项-benchtime Nx.

例子:

go test -bench=. -benchtime 100x
Run Code Online (Sandbox Code Playgroud)

基准测试 100 ... ns/操作

请在此处阅读有关所有 go 测试标志的更多信息。


met*_*ule 4

请参阅Description_of_testing_flags

-bench regexp
    Run benchmarks matching the regular expression.
    By default, no benchmarks run. To run all benchmarks,
    use '-bench .' or '-bench=.'.
Run Code Online (Sandbox Code Playgroud)

-check.b工作方式与 相同-test.bench

例如运行所有基准测试:

go test -check.b=.
Run Code Online (Sandbox Code Playgroud)

运行特定的基准测试:

go test -check.b=BenchmarkLogic
Run Code Online (Sandbox Code Playgroud)

有关 Go 测试的更多信息可以在这里找到

  • 您没有回答问题:如何指定 N (2认同)