Skip to content

Latest commit

 

History

History
48 lines (34 loc) · 937 Bytes

File metadata and controls

48 lines (34 loc) · 937 Bytes

Python example for benchmarking with [pytest-benchmark][tool]

Run benchmarks

Official documentation for usage of pytest-benchmark:

https://pytest-benchmark.readthedocs.io/en/stable/

Install dependencies with venv package using Python3.

$ python -m venv venv
$ source venv/bin/activate
$ pip install pytest pytest-benchmark

Prepare bench.py as follows:

e.g.

import pytest

def some_test_case(benchmark):
    benchmark(some_func, args)

And run benchmarks with --benchmark-json in workflow. The JSON file will be an input to github-action-benchmark.

e.g.

- name: Run benchmark
  run: pytest bench.py --benchmark-json output.json

Process benchmark results

- name: Compare benchmark result
  uses: larabr/github-action-benchmark@v1
  with:
    tool: 'pytest'
    pr-benchmark-file-path: output.json
    ...