百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
G

geiger

> 编程语言
开源

C++ 微型基准库

99 stars0 点赞3 次浏览
访问官网GitHub

工具介绍

C++ 微型基准库

geiger

A micro benchmark library in C++ that supports hardware performance counters.

Why and what ?

  • Because you cannot do a micro-benchmark by running perf
  • Simple API, header-only library
  • Each test is run either a number of iterations or a specified time

Build & install

bash
$ mkdir build && cd build
$ cmake -DCMAKE_INSTALL_PREFIX=/usr ..
$ make
# make install

Examples

Time measurement

The simplest usage of geiger is to measure the time required for a task:

…

This code will output:

  Test              Time (ns)
  ---------------------------
  rand                     14
  vector push_back         47

By default - as in the example above - each test is running during one second. Here, the "rand" test has then been executed tens of thousands of times, and the average execution time was 14ns.

You can specify the duration you want as argument to geiger::suite::run()...

cpp
      // Run each test during one millisecond
      s.run(std::chrono::milliseconds(1));

... or a number of iterations:

cpp
      // Run each test exactly 100 times
      s.run(100);

Simply be aware that a too short time - or a too low number of iterations - can result in less accurate measurements.

When specifying a duration, before running the benchmark, geiger is performing a calibration stage where it approximates the number of iterations required to run this task during the specified time.


Hardware counters

A more advanced usage of geiger is to include hardware counters. This is done by specifying a list of papi_wrapper in the template parameters list of geiger::suite<>:

cpp
      // cache_profiler reports the number of L1, L2 and L3 cache misses.
      suite s;
 
      s.add("linear walk", linear_walk())
       .add("random walk", random_walk());

      s.run();

The output is now also displaying the number of hardware events per test run.

Test                Time (ns)      PAPI_L1_DCM      PAPI_L2_DCM      PAPI_L3_TCM
--------------------------------------------------------------------------------
linear walk                88                1                0                0
random walk               613               64               64               55

You can cover the events you want by defining your own PAPI wrapper. For example, if you are interested by events around branch predictions:

cpp
      // Measuring branches taken, not taken, mispredicted and correctly predicted
      using branch_profiler = papi_wrapper

      suite s;

Events

Implementation details

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

C++

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言