ASV Runner
ASV Runner is the pure Python core of ASV (Airspeed-Velocity), providing essential functionality for running Python benchmarks with minimal dependencies. It focuses on the execution, timing, and memory measurement of benchmark code. The library's current version is 0.2.1, and it typically releases updates a few times a year, often in conjunction with the main `asv` package.
Common errors
-
ModuleNotFoundError: No module named 'asv_runner'
cause The 'asv_runner' package is not installed in the Python environment.fixInstall the package using pip: 'pip install asv_runner'. -
ImportError: cannot import name 'Benchmark' from 'asv_runner'
cause The 'Benchmark' class is not available in the 'asv_runner' module.fixEnsure you are importing the correct class or function from 'asv_runner'. Refer to the official documentation for the correct import statements. -
TypeError: 'NoneType' object is not callable
cause Attempting to call a function or method that is None, possibly due to a failed import or incorrect assignment.fixVerify that all necessary modules and functions are correctly imported and initialized before use. -
AttributeError: module 'asv_runner' has no attribute 'run_benchmark'
cause The 'asv_runner' module does not have a 'run_benchmark' attribute, possibly due to a version mismatch or incorrect import.fixCheck the module's documentation to confirm the available attributes and ensure you are using the correct version of 'asv_runner'. -
ValueError: Invalid benchmark configuration
cause The benchmark configuration provided is invalid or missing required parameters.fixReview the benchmark configuration settings and ensure all required parameters are correctly specified as per the documentation.
Warnings
- breaking With the release of `asv` version 0.6.0, the project's functionality was split into the main `asv` package and `asv_runner`. `asv_runner` now strictly handles the core benchmark execution. Users or developers who previously relied on internal `asv` mechanisms for benchmark running prior to 0.6.0 may find their code no longer compatible if they attempt to interact directly with these components.
- deprecated Raising `NotImplementedError` directly from a benchmark function to skip it is deprecated. While it may still work in some contexts for backward compatibility, the recommended approach is to raise `asv_runner.benchmark.mark.SkipNotImplemented` or use the `skip_benchmark_if`/`skip_params_if` decorators.
- gotcha ASV Runner (`asv-runner`) is primarily a low-level component designed to be used by the higher-level `asv` benchmarking tool. Most users should interact with the `asv` command-line interface (e.g., `asv run`, `asv quickstart`) or import from the main `asv` package for comprehensive benchmarking, environment management, and result analysis. Attempting to directly import and use `asv_runner` modules for high-level tasks will result in incomplete functionality and a lack of orchestration.
- gotcha ASV Runner, when invoked by `asv`, automatically computes a 'version number' for each benchmark based on its source code. If the benchmark's code changes, this version number updates, causing `asv` to ignore previously collected results for that benchmark. This can lead to unexpected re-benchmarking if not understood.
Install
-
pip install asv-runner
Imports
- Benchmark
from asv_runner.benchmarks._base import Benchmark
- time_range
from my_project.benchmarks import time_range
- SkipNotImplemented
from asv_runner.benchmark.mark import SkipNotImplemented
Quickstart
# my_project/benchmarks.py
class TimeSuite:
def setup(self):
self.data = list(range(1_000_000))
def time_iterate_list(self):
for _ in self.data:
pass
def time_sum_list(self):
sum(self.data)
# To run this, you would typically use the `asv` command-line tool:
# 1. Initialize an ASV project: `asv quickstart` (creates asv.conf.json, etc.)
# 2. Place this file in your benchmark directory (e.g., 'benchmarks/')
# 3. Run benchmarks: `asv run`