Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
G

geiger

> 编程语言
Open source

C++ micro benchmark library

99 stars0 likes3 views
WebsiteGitHub

About

C++ micro benchmark library

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 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

C++

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 18, 2026
Category编程语言
PricingOpen source

> Related tools

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