google-benchmark
A library to benchmark code snippets.
What it is and what it does
google-benchmark is a Python wrapper around Google's C++ benchmarking library, designed to measure and compare the performance of code snippets with statistical rigor. Unlike simple timing, it runs code multiple times under controlled conditions to produce reliable performance metrics. The library is modeled after unit-testing frameworks, so if you've used pytest or similar tools, the structure will feel familiar.
You define benchmark functions, register them with decorators or macros, and run them to get detailed timing statistics. It has no runtime dependencies beyond Python itself, making it lightweight to deploy. The package supports Python 3.10 through 3.13 and is actively maintained; precompiled wheels are available for common platforms (macOS, Linux, Windows across x86_64 and ARM architectures).
Use it for:
- Measure and compare performance of different algorithm implementations to choose the fastest one
- Track performance regressions in CI/CD pipelines by benchmarking code before and after changes
- Profile hot paths in Python applications to identify optimization targets
- Generate reproducible performance reports for code review and documentation
- Validate that optimizations actually improve performance with statistical confidence
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Provides Python bindings to Google's C++ benchmarking library, allowing you to measure and compare the performance of code snippets with statistical rigor.
Yes, if you need rigorous performance measurement. The library is actively maintained, has no runtime dependencies, and Apache-2.0 licensing poses no restrictions. Medium install friction is acceptable for a compiled package with broad platform support. Best suited for developers who want statistical benchmarking beyond simple timing—if you only need quick profiling, lighter tools may suffice.
Install
google-benchmark on PyPI
pip
pip install google-benchmarkuv
uv add google-benchmarkpoetry
poetry add google-benchmarkInstalling google-benchmark
Before you install
Medium install friction due to compiled wheels for multiple platforms and Python versions (3.10–3.13). Active maintenance with recent releases; no runtime dependencies simplifies deployment once installed.
License in practice
Apache-2.0 permissive license allows use in proprietary and open-source projects with minimal restrictions; attribution required.
Quickstart
pip install google-benchmark
import benchmark
@benchmark.register
def BM_example(state):
for _ in state:
# Code to measure
pass
Requires Python 3.10 or later; precompiled wheels available for macOS (x86_64, arm64), Linux (x86_64, aarch64), and Windows (amd64).
Verify before relying
- Exact API surface and decorator/function signatures for Python bindings beyond the C++ example shown
- Whether the package includes statistical analysis features (e.g., confidence intervals, regression detection) mentioned in the C++ docs
- Performance overhead of the Python binding layer compared to native C++ benchmarking
Package facts
| License | Apache-2.0 (permissive) |
| Python support | supports the current Python release (>=3.10) |
| Install friction | medium — platform-specific wheel |
| Runtime dependencies | none |
| Maintenance | actively maintained — 193 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 75,335/month — #14,726 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: google_benchmark-1.9.5-cp310-cp310-macosx_10_14_x86_64.whl; google_benchmark-1.9.5-cp310-cp310-macosx_11_0_arm64.whl; google_benchmark-1.9.5-cp310-cp310-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl; google_benchmark-1.9.5-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl; google_benchmark-1.9.5-cp310-cp310-win_amd64.whl; google_benchmark-1.9.5-cp311-cp311-macosx_10_14_x86_64.whl; google_benchmark-1.9.5-cp311-cp311-macosx_11_0_arm64.whl; google_benchmark-1.9.5-cp311-cp311-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl; google_benchmark-1.9.5-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl; google_benchmark-1.9.5-cp311-cp311-win_amd64.whl; google_benchmark-1.9.5-cp312-abi3-macosx_10_14_x86_64.whl; google_benchmark-1.9.5-cp312-abi3-macosx_11_0_arm64.whl; google_benchmark-1.9.5-cp312-abi3-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl; google_benchmark-1.9.5-cp312-abi3-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl; google_benchmark-1.9.5-cp312-abi3-win_amd64.whl
Keywords: benchmark
Tags
More Testing packages
Pluggy provides a plugin system that lets you…
permissive · top 100 on PyPI
pytestpytest is a testing framework that lets you…
permissive · top 100 on PyPI
virtualenvvirtualenv creates isolated Python environments…
permissive · top 100 on PyPI
coverageCoverage.py measures which lines of Python code…
permissive · top 1,000 on PyPI
pytest-asynciopytest-asyncio is a pytest plugin that enables…
permissive · top 1,000 on PyPI
pytest-json-ctrfA pytest plugin that generates test reports in…
permissive · top 1,000 on PyPI
whylogs-sketchingProvides Python bindings to Apache…
permissive · top 15,000 on PyPI
pytest-benchmarkA pytest fixture that benchmarks Python…
permissive · top 5,000 on PyPI
pyperfpyperf is a toolkit for writing, running, and…
permissive · top 15,000 on PyPI
msbench-utilsProvides utility functions and helpers for…
permissive · top 15,000 on PyPI
codeflash-benchmarkA pytest plugin that adds benchmarking…
unclear · top 15,000 on PyPI
pytest-cmakeIntegrates Pytest with CMake build systems,…
permissive · top 15,000 on PyPI
pytest-codspeedA pytest plugin that integrates performance…
permissive · top 5,000 on PyPI
asvasv benchmarks Python packages over their…
permissive · top 15,000 on PyPI
asv-runnerProvides core Python benchmark execution code…
permissive · top 15,000 on PyPI
libkvikio-cu12libkvikio-cu12 provides Python and C++ bindings…
permissive · top 15,000 on PyPI