本文作者原创,首发在本博客;CSDN 上的同名文章已标注为转载并回链到本页:https://blog.csdn.net/qq_30220519/article/details/155111356
改造benchmark,运行中获取ns耗时
benchmark.cc
double State::real_time_used() const {
return timer_->real_time_used();
}
定义测试套件
1 | class PerfTest : public benchmark::Fixture { |
输出基准报告
-—————————————————————————————
Benchmark Time CPU Iterations UserCounters…
-—————————————————————————————
PerfTest/sleepTest 1010025320 ns 0.000 ns 10 F=0 S=2
PerfTest/sleepTest ERROR OCCURRED: ‘fail actual 0.000699s,4559561393.000000HZ - expect 0.000500s,4503077393.000000HZ = 0.000199s’
使用
1 |
|
静态库使用
1 add_definitions(-DBENCHMARK_STATIC_DEFINE)
参考
https://github.com/google/benchmark
创作不易,小小的支持一下吧!

