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):
    @benchmark
    def result():
        # Code to be measured
        return 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-min-time=BENCHMARK_MIN_TIME

Minimum time per round.

--benchmark-max-time=BENCHMARK_MAX_TIME

Maximum time to spend in a benchmark.

--benchmark-min-rounds=BENCHMARK_MIN_ROUNDS

Minimum rounds, even if total time would exceed –max-time.

--benchmark-sort=BENCHMARK_SORT

Column to sort on. Can be one of: ‘min’, ‘max’, ‘mean’ or ‘stddev’ .

--benchmark-timer=BENCHMARK_TIMER

Timer to use when measuring time.

--benchmark-warmup

Runs the benchmarks two times. Discards data from the first run.

--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",
    min_time=0.1,
    max_time=0.5,
    min_rounds=5,
    timer=time.time,
    disable_gc=True,
    warmup=False
)
def test_my_stuff(benchmark):
    @benchmark
    def result():
        # Code to be measured
        return 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

Credits

Changelog

2.0.0 (2014-12-19)

  • Replace the context-manager based API with a simple callback interface.

  • Implement timer calibration for precise measurements.

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

Uploaded Source

Built Distribution

pytest_benchmark-2.0.0-py2.py3-none-any.whl (16.3 kB view details)

Uploaded Python 2 Python 3

File details

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

File metadata

File hashes

Hashes for pytest-benchmark-2.0.0.tar.gz
Algorithm Hash digest
SHA256 83efdd09897862ef664172bd7dbf1e552b40a613eeb82702a80daa0db6a497d0
MD5 a6d9d2c4c794427d5939cb41c3c90ceb
BLAKE2b-256 a641993d4e52bd9674642fbfa5f01c7338d34d0d0a0e3687b81236488bbcb1d2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytest_benchmark-2.0.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 dbb695e443838f75000b5570cbb5926c2da2027ac474cebb3f41d3ba340b69cb
MD5 43aafb8dca5d8a4a0610f1af2b4c3f5f
BLAKE2b-256 7bcc1941605881ec8012b8537b534f7381d14e630c5aa31758b4c04ad3eef0bd

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