There are no benchmark tests for codec encode/decode operations. This makes it difficult to detect performance regressions.
Proposed Solution
Add tests/test_benchmarks.py:
import pytest
from dag import Block
from dag.codecs import dag_cbor, dag_json, dag_pb, raw
BENCH_DATA = {"key": "value", "number": 42, "list": [1, 2, 3]}
BENCH_BYTES = dag_cbor.encode(BENCH_DATA)
@pytest.mark.benchmark
def test_bench_dag_cbor_encode(benchmark):
benchmark(dag_cbor.encode, BENCH_DATA)
@pytest.mark.benchmark
def test_bench_dag_cbor_decode(benchmark):
benchmark(dag_cbor.decode, BENCH_BYTES)
@pytest.mark.benchmark
def test_bench_dag_json_encode(benchmark):
benchmark(dag_json.encode, BENCH_DATA)
@pytest.mark.benchmark
def test_bench_dag_json_decode(benchmark):
benchmark(dag_json.decode, dag_json.encode(BENCH_DATA))
@pytest.mark.benchmark
def test_bench_block_encode(benchmark):
benchmark(Block.encode, value=BENCH_DATA, codec=dag_cbor.codec)
@pytest.mark.benchmark
def test_bench_block_decode(benchmark):
benchmark(Block.decode, data=BENCH_BYTES, codec=dag_cbor.codec)
Related
- Dev dependency to add:
pytest-benchmark
There are no benchmark tests for codec encode/decode operations. This makes it difficult to detect performance regressions.
Proposed Solution
Add
tests/test_benchmarks.py:Related
pytest-benchmark