A Python library to benchmark code snippets, wrapping the C++ Google Benchmark library. Version 1.9.5 requires Python >=3.10 and provides a simple API for timing code execution and comparing performance.
pip install google-benchmarkVerified import paths — ran on the pinned version, not inferred.
Register a benchmark function and run with benchmark.main().
Replace 'import benchmark' with 'import google_benchmark as benchmark'.
Always include 'for _ in state:' inside your benchmark function.
Ensure your benchmark function accepts exactly one argument (the state object).
Use register with custom setup/teardown inside the benchmark function or wait for new fixture API.
Install the correct package: pip install google-benchmark, then import as import google_benchmark as benchmark.
Uninstall the old package (pip uninstall benchmark) and install google-benchmark (pip install google-benchmark). Then use import google_benchmark as benchmark.
Add state parameter: def my_benchmark(state): and use for _ in state: inside.