Skip to main content

py.test fixture for benchmarking code

Project description

Documentation Status Travis-CI Build Status AppVeyor Build Status Coverage Status Code Quality Status Scrtinizer Status
PyPI Package latest release PyPI Package monthly downloads PyPI Wheel Supported versions Supported imlementations

A py.test fixture for benchmarking code.

  • Free software: BSD license

Installation

pip install pytest-benchmark

Usage

def test_my_stuff(benchmark):
    with benchmark:
        # Code to be measured
        result = time.sleep(0.000001)

    # Extra code, to verify that the run completed correctly.
    # Note: this code is not measured.
    assert result is None

py.test command-line options:

--benchmark-max-time=BENCHMARK_MAX_TIME

Maximum time to spend in a benchmark (including overhead).

--benchmark-max-iterations=BENCHMARK_MAX_ITERATIONS

Maximum iterations to do.

--benchmark-min-iterations=BENCHMARK_MIN_ITERATIONS

Minium iterations, even if total time would exceed max-time.

--benchmark-scale=BENCHMARK_SCALE

Minium iterations, even if total time would exceed max-time.

--benchmark-timer=BENCHMARK_TIMER

Timer to use when measuring time.

--benchmark-disable-gc

Disable GC during benchmarks.

--benchmark-skip

Skip running any benchmarks.

--benchmark-only

Only run benchmarks.

Setting per-test options:

@pytest.mark.benchmark(
    group="group-name", max_time=0.5,
    max_iterations=5000, min_iterations=5,
    timer=time.time, disable_gc=True)
def test_my_stuff(benchmark):
    with benchmark:
        # Code to be measured
        result = time.sleep(0.000001)

    # Extra code, to verify that the run
    # completed correctly.
    # Note: this code is not measured.
    assert result is None

Documentation

https://pytest-benchmark.readthedocs.org/

Obligatory screenshot

Screenshot of py.test summary

Development

To run the all tests run:

tox

Changelog

1.0.0 (2014-12-15)

  • Use a precise default timer for PyPy.

? (?)

  • Readme and styling fixes (contributed by Marc Abramowitz)

  • Lots of wild changes.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pytest-benchmark-1.1.0.tar.gz (28.0 kB view details)

Uploaded Source

Built Distribution

pytest_benchmark-1.1.0-py2.py3-none-any.whl (9.0 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file pytest-benchmark-1.1.0.tar.gz.

File metadata

File hashes

Hashes for pytest-benchmark-1.1.0.tar.gz
Algorithm Hash digest
SHA256 992f4b942e6c8baea58cb14238c9977b2b239ee391af60c09915e85cf8ad5f32
MD5 9227a736321b412b455242ce12ca4b02
BLAKE2b-256 09d69f10ee3642896f678df6057b8ffe44ab9ca6510b0e77cca5029562cfaad8

See more details on using hashes here.

File details

Details for the file pytest_benchmark-1.1.0-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for pytest_benchmark-1.1.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 2f3a6ea3f56d3fe16281917e369df5545c2de4d5eaf82a83b1a8d3c7ee3baa6e
MD5 1a3ef7323ff2796fa19c7796d4d7dec6
BLAKE2b-256 be7c8f2e3c204e462c3e05832d89e3858ace25a9d15979feb2b995dd4472fa75

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page