Google Benchmark

google-benchmark 下载与README 地址

https://github.com/google/benchmark

源码的编译和执行

源码

test.cpp 这个一个测试memcpy对不同大小的内存的执行效率的函数。

#include <benchmark/benchmark.h>
#include <string.h>

static void BM_memcpy(benchmark::State& state) {
  char* src = new char[state.range_x()]; char* dst = new char[state.range_x()];
  memset(src, 'x', state.range_x());
  while (state.KeepRunning())
    memcpy(dst, src, state.range_x());
  state.SetBytesProcessed(int64_t(state.iterations()) *
                          int64_t(state.range_x()));
  delete[] src; delete[] dst;
}
BENCHMARK(BM_memcpy)->Arg(8)->Arg(64)->Arg(512)->Arg(1<<10)->Arg(8<<10);
BENCHMARK_MAIN();

编译

g++ test.cpp -std=c++11 -lpthread -lbenchmark

运行 a.out 运行结果

含义 :

名字 + 运行一次的User时间 + 一次的CPU时间 + 1s 可以迭代多少次

源码解析

results matching ""

    No results matching ""