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

0.1.0 (2014-10-10)

  • First release on PyPI.

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-0.11.0.tar.gz (27.5 kB view details)

Uploaded Source

Built Distribution

pytest_benchmark-0.11.0-py2.py3-none-any.whl (8.6 kB view details)

Uploaded Python 2 Python 3

File details

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

File metadata

File hashes

Hashes for pytest-benchmark-0.11.0.tar.gz
Algorithm Hash digest
SHA256 9dc2d0dc3d4f97fa8eb9d7baa7360a5bdbde56f73f184c9a4a34ef96b475822b
MD5 f334d96ec16da398778f6e2286d9c32c
BLAKE2b-256 0bef20e1aec88a52cdb32f13a4045b24c6e4af791d013db3ef1e60c369d7e280

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytest_benchmark-0.11.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 e31e9338e68c8f5b7ec8e333cab311d68972b92656df308a478d62817b676b5b
MD5 7cb499df9c544fd4ff8064ca2467f74b
BLAKE2b-256 cc8155481ba4b5b17625101581e7439628372d7b3c812afb1d8426d10a8709af

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