From f67d50f33a457da9104533400eb8cf32137dbfdf Mon Sep 17 00:00:00 2001 From: sumanjeet0012 Date: Mon, 13 Jul 2026 14:23:40 +0530 Subject: [PATCH 1/2] test: add benchmark tests for encode/decode operations --- pyproject.toml | 1 + tests/test_benchmarks.py | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 tests/test_benchmarks.py diff --git a/pyproject.toml b/pyproject.toml index 01f775d..6e258f4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -41,6 +41,7 @@ dev = [ "mypy", "pre-commit", "pytest", + "pytest-benchmark", "pytest-runner", "ruff", "towncrier>=24,<25", diff --git a/tests/test_benchmarks.py b/tests/test_benchmarks.py new file mode 100644 index 0000000..1804b14 --- /dev/null +++ b/tests/test_benchmarks.py @@ -0,0 +1,22 @@ +import pytest +from multibase import encode, decode, ENCODINGS + +BENCH_DATA = b"Decentralize everything!!!" + +@pytest.mark.benchmark +@pytest.mark.parametrize("encoding_info", ENCODINGS, ids=lambda e: e.encoding) +def test_bench_encode(benchmark, encoding_info): + benchmark(encode, encoding_info.encoding, BENCH_DATA) + +@pytest.mark.benchmark +@pytest.mark.parametrize("encoding_info", ENCODINGS, ids=lambda e: e.encoding) +def test_bench_decode(benchmark, encoding_info): + encoded = encode(encoding_info.encoding, BENCH_DATA) + benchmark(decode, encoded) + +@pytest.mark.benchmark +@pytest.mark.parametrize("encoding_info", ENCODINGS, ids=lambda e: e.encoding) +def test_bench_roundtrip(benchmark, encoding_info): + def roundtrip(): + return decode(encode(encoding_info.encoding, BENCH_DATA)) + benchmark(roundtrip) From 3daab431270ed211cc5d1a5fcd679394986b5e44 Mon Sep 17 00:00:00 2001 From: sumanjeet0012 Date: Mon, 13 Jul 2026 19:10:45 +0530 Subject: [PATCH 2/2] style: fix linting issues --- tests/test_benchmarks.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tests/test_benchmarks.py b/tests/test_benchmarks.py index 1804b14..336dc29 100644 --- a/tests/test_benchmarks.py +++ b/tests/test_benchmarks.py @@ -1,22 +1,27 @@ import pytest -from multibase import encode, decode, ENCODINGS + +from multibase import ENCODINGS, decode, encode BENCH_DATA = b"Decentralize everything!!!" + @pytest.mark.benchmark @pytest.mark.parametrize("encoding_info", ENCODINGS, ids=lambda e: e.encoding) def test_bench_encode(benchmark, encoding_info): benchmark(encode, encoding_info.encoding, BENCH_DATA) + @pytest.mark.benchmark @pytest.mark.parametrize("encoding_info", ENCODINGS, ids=lambda e: e.encoding) def test_bench_decode(benchmark, encoding_info): encoded = encode(encoding_info.encoding, BENCH_DATA) benchmark(decode, encoded) + @pytest.mark.benchmark @pytest.mark.parametrize("encoding_info", ENCODINGS, ids=lambda e: e.encoding) def test_bench_roundtrip(benchmark, encoding_info): def roundtrip(): return decode(encode(encoding_info.encoding, BENCH_DATA)) + benchmark(roundtrip)