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

nanobench

> 编程语言
Open source

Simple, fast, accurate single-header microbenchmarking functionality for C++11/14/17/20

1.7K stars0 likes0 views
WebsiteGitHub

About

Simple, fast, accurate single-header microbenchmarking functionality for C++11/14/17/20

ankerl::nanobench

ankerl::nanobench is a platform independent microbenchmarking library for C++11/14/17/20.

#define ANKERL_NANOBENCH_IMPLEMENT
#include <nanobench.h>

int main() {
    double d = 1.0;
    ankerl::nanobench::Bench().run("some double ops", [&] {
        d += 1.0 / d;
        if (d > 5.0) {
            d -= 5.0;
        }
        ankerl::nanobench::doNotOptimizeAway(d);
    });
}

The whole executable runs for ~60ms and prints

|               ns/op |                op/s |    err% |          ins/op |          cyc/op |    IPC |         bra/op |   miss% |     total | benchmark
|--------------------:|--------------------:|--------:|----------------:|----------------:|-------:|---------------:|--------:|----------:|:----------
|                7.52 |      132,948,239.79 |    1.1% |            6.65 |           24.07 |  0.276 |           1.00 |    8.9% |      0.00 | `some double ops`

Which github renders as

ns/op op/s err% ins/op cyc/op IPC bra/op miss% total benchmark 7.52 132,948,239.79 1.1% 6.65 24.07 0.276 1.00 8.9% 0.00 some double ops

The benchmarked code takes 7.52 nanoseconds to run, so ~133 million times per seconds. Measurements fluctuate by 1.1%. On average 6.65 instructions are executed in 24.07 CPU cycles, resulting in 0.276 instructions per cycle. A single branch is in the code, which branch prediction missed in 8.9% of the cases. Total runtime of the benchmark with the name some double ops is 0.00, so just a few milliseconds.

Design Goals

  • Ease of use: Simple & powerful API, fast compile times, easy to integrate anywhere.
  • Fast: Get accurate results as fast as possible. nanobench is ~80 times faster than google benchmark.
  • Accurate: Get deterministic, repeatable, and accurate results that you can make sound decisions on.
  • Robust: Be robust against outliers, warn if results are not reliable.

Documentation

Extensive documentation is available.

More

  • Code of Conduct - Contributor Covenant Code of Conduct

GitHub Issues· 0 open

View all on GitHub

No open issues yet, or sync has not completed.

Highlights

  • •Ease of use: Simple & powerful API, fast compile times, easy to integrate anywhere.
  • •Fast: Get accurate results as fast as possible. nanobench is ~80 times faster than google benchmark.
  • •Accurate: Get deterministic, repeatable, and accurate results that you can make sound decisions on.
  • •Robust: Be robust against outliers, warn if results are not reliable.
  • •Code of Conduct - Contributor Covenant Code of Conduct

> Tags

C++benchmarkcppcpp11header-only

No comments yet. Be the first to share.

> Details

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

> Related tools

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