Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions newsfragments/54.misc.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add optional ``pytest-benchmark`` suite for ``sum`` / ``encode`` / ``decode`` (excluded from default CI via the ``benchmark`` marker).
5 changes: 5 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ dev = [
"pre-commit",
"pycryptodome>=3.0,<4.0",
"pytest",
"pytest-benchmark",
"pytest-cov",
"pytest-runner",
"ruff",
Expand All @@ -65,6 +66,10 @@ include = ["multihash*"]
[tool.pytest.ini_options]
testpaths = ["tests"]
python_classes = "*TestCase"
addopts = "-m 'not benchmark'"
markers = [
"benchmark: performance benchmarks (excluded from default test runs)",
]

[tool.towncrier]
# Read https://github.com/multiformats/py-multihash/blob/master/newsfragments/README.md for instructions
Expand Down
43 changes: 43 additions & 0 deletions tests/test_benchmarks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
"""Benchmark tests for core multihash operations.

Excluded from default ``make test`` / tox core runs via the ``benchmark`` marker.
Run explicitly with::

pytest -m benchmark tests/test_benchmarks.py
"""

import pytest

from multihash import Func, decode, sum

BENCH_DATA = b"benchmark test data for multihash operations" * 100

pytestmark = pytest.mark.benchmark


def test_bench_sum_sha256(benchmark):
benchmark(sum, BENCH_DATA, Func.sha2_256)


def test_bench_sum_sha512(benchmark):
benchmark(sum, BENCH_DATA, Func.sha2_512)


def test_bench_sum_blake3(benchmark):
benchmark(sum, BENCH_DATA, Func.blake3)


@pytest.mark.parametrize("bits", [8, 128, 256, 384, 512])
def test_bench_sum_blake2b(benchmark, bits):
func = getattr(Func, f"blake2b_{bits}")
benchmark(sum, BENCH_DATA, func)


def test_bench_encode(benchmark):
mh = sum(BENCH_DATA, Func.sha2_256)
benchmark(mh.encode)


def test_bench_decode(benchmark):
encoded = sum(BENCH_DATA, Func.sha2_256).encode()
benchmark(decode, encoded)
24 changes: 24 additions & 0 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading