I was looking for a way to benchmark a piece of code… I came up with 5 libraries that make it very easy 🙂

I’m not going to write a tutorial on how to use each one because I would basically be rewriting their documentation sections. What I will do is show you how to get started. As an example I will write a simple benchmark that tests copy constructor of std::string. But first, the libraries:

  1. Google Benchmark
  2. Catch2
  3. Hayai
  4. Celero
  5. Nonius

Catch2 and Nonius are header only libraries; be aware of long compile times 🙁 Google, Catch2, and Nonius automatically pick the number of runs and iterations for you, which is nice: no guessing how many times you need to run a function you want to benchmark to get a reasonable performance reading.


Google Benchmark:



Catch2:



Hayai:



Celero:



Nonius:



2 Replies to “Micro-benchmarks”

Leave a Reply