douzi8548 2013-04-23 04:46
浏览 73
已采纳

如何仅测试一个基准功能?

In my Go package there are several benchmark files like map1_benchmark_test.go and map2_benchmark_test.go. In every *_benchmark_test.go file, there is more than one benchmark function like func BenchmarkMapTravel(b *testing.B) and func BenchmarkMapGet(b *testing.B).

Question is, how can I test just one benchmark function?

I attempted to read some manuals, and got nothing about benchmark by running go help test.

  • 写回答

3条回答 默认 最新

  • dow46218 2013-04-23 05:26
    关注

    Description of testing flags

    -test.bench pattern
        Run benchmarks matching the regular expression.
        By default, no benchmarks run.
    
    -test.run pattern
        Run only those tests and examples matching the regular
        expression.
    

    For convenience, each of these -test.X flags of the test binary is also available as the flag -X in 'go test' itself.

    For help,

    $ go help testflag
    

    For example,

    go test -test.bench MapTravel
    go test -test.bench MapGet
    

    or

    go test -bench MapTravel
    go test -bench MapGet
    

    To bypass test functions, include a -test.run pattern that filters out every single test. For example,

    go test -test.bench MapTravel -test.run=thisexpressionwontmatchanytest
    

    or

    go test -bench MapTravel -run=^$
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 高价求中通快递查询接口
  • ¥15 解决一个加好友限制问题 或者有好的方案
  • ¥15 急matlab编程仿真二阶震荡系统
  • ¥20 TEC-9的数据通路实验
  • ¥15 ue5 .3之前好好的现在只要是激活关卡就会崩溃
  • ¥50 MATLAB实现圆柱体容器内球形颗粒堆积
  • ¥15 python如何将动态的多个子列表,拼接后进行集合的交集
  • ¥20 vitis-ai量化基于pytorch框架下的yolov5模型
  • ¥15 如何实现H5在QQ平台上的二次分享卡片效果?
  • ¥30 求解达问题(有红包)