Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/martinus/nanobench
Simple, fast, accurate single-header microbenchmarking functionality for C++11/14/17/20
https://github.com/martinus/nanobench
benchmark cpp cpp11 header-only microbenchmark single-file single-header single-header-lib
Last synced: 3 days ago
JSON representation
Simple, fast, accurate single-header microbenchmarking functionality for C++11/14/17/20
- Host: GitHub
- URL: https://github.com/martinus/nanobench
- Owner: martinus
- License: mit
- Created: 2019-10-05T21:39:18.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2024-10-06T07:15:00.000Z (3 months ago)
- Last Synced: 2025-01-02T23:03:26.613Z (10 days ago)
- Topics: benchmark, cpp, cpp11, header-only, microbenchmark, single-file, single-header, single-header-lib
- Language: C++
- Homepage: https://nanobench.ankerl.com
- Size: 7.49 MB
- Stars: 1,467
- Watchers: 20
- Forks: 84
- Open Issues: 22
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
- Code of conduct: docs/CODE_OF_CONDUCT.html
Awesome Lists containing this project
- awesome-performance - nanobench
- AwesomeCppGameDev - nanobench - header microbenchmarking functionality for C++11/14/17/20 (C++)
- awesome-hpp - nanobench - MIT-yellow.svg)](https://opensource.org/licenses/MIT) | (Benchmarking)
README
![ankerl::nanobench logo](src/docs/nanobench-logo-small.svg)
[![Release](https://img.shields.io/github/release/martinus/nanobench.svg)](https://github.com/martinus/nanobench/releases)
[![GitHub license](https://img.shields.io/github/license/martinus/nanobench.svg)](https://raw.githubusercontent.com/martinus/nanobench/master/LICENSE)
[![Travis CI Build Status](https://travis-ci.com/martinus/nanobench.svg?branch=master)](https://travis-ci.com/martinus/nanobench)
[![Appveyor Build Status](https://ci.appveyor.com/api/projects/status/github/martinus/nanobench?branch=master&svg=true)](https://ci.appveyor.com/project/martinus/nanobench)
[![Join the chat at https://gitter.im/nanobench/community](https://badges.gitter.im/nanobench/community.svg)](https://gitter.im/nanobench/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)`ankerl::nanobench` is a platform independent microbenchmarking library for C++11/14/17/20.
```cpp
#define ANKERL_NANOBENCH_IMPLEMENT
#includeint 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
```markdown
| 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](https://nanobench.ankerl.com/reference.html), fast compile times, [easy to integrate anywhere](https://nanobench.ankerl.com/tutorial.html#installation).
* **Fast**: Get accurate results as fast as possible. nanobench is [~80 times faster than google benchmark](https://nanobench.ankerl.com/comparison.html#runtime).
* **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](https://nanobench.ankerl.com).
# More
* [Code of Conduct](src/docs/CODE_OF_CONDUCT.md) - Contributor Covenant Code of Conduct
* I need a better logo. Currently I use a small bench. Nanobench. Ha ha.