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. Default: 25.00us

--benchmark-max-time=BENCHMARK_MAX_TIME

Maximum time to spend in a benchmark. Default: 1.00s

--benchmark-min-rounds=BENCHMARK_MIN_ROUNDS

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

--benchmark-sort=BENCHMARK_SORT

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

--benchmark-timer=BENCHMARK_TIMER

Timer to use when measuring time. Default: time.perf_counter

--benchmark-warmup

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

--benchmark-verbose

Dump diagnostic and progress information.

--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.2.0 (2014-12-26)

  • Make the default rounds smaller (so that variance is more accurate).

  • Show the defaults in the --help section.

2.1.0 (2014-12-20)

  • Simplify the calibration code so that the round is smaller.

  • Add diagnostic output for calibration code (--benchmark-verbose).

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

Uploaded Source

Built Distribution

pytest_benchmark-2.2.0-py2.py3-none-any.whl (17.3 kB view details)

Uploaded Python 2 Python 3

File details

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

File metadata

File hashes

Hashes for pytest-benchmark-2.2.0.tar.gz
Algorithm Hash digest
SHA256 78b2adc9b53523c2d549080c804dfef82e612cc10452461148a414f6b8564631
MD5 d518b614c7bbe65e2dc3ab23a0a6ac18
BLAKE2b-256 4f160cae03e2dc00b22e2d7eed3687695926f5f03ca18120aac160b78b5f4b1d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytest_benchmark-2.2.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 731c4f9d9bc6f6ac8561335b5d933b3004754992b786ddd83a2e5550cc5769c9
MD5 a3102da25ea116c2ce8320b5831987ec
BLAKE2b-256 f676a3b61be3114aeee773598569e46696d0f71062ef46242ec806ab88732023

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