Skip to content

No benchmark tests for sum(), encode(), decode() operations #54

Description

@sumanjeet0012

There are no benchmark tests. go-multihash includes BenchmarkSum, BenchmarkEncode, BenchmarkDecode, BenchmarkBlake2B, and BenchmarkSumAllLarge which help catch performance regressions.

Problem

The test suite has functional tests but zero benchmarks. Operations like Blake2b hashing (which has 64 variants) and SHAKE variable-length hashing have no performance baseline.

Proposed Solution

  1. Install pytest-benchmark as a dev dependency.

  2. Create tests/test_benchmarks.py:

    import pytest
    from multihash import sum, encode, decode, Func
    
    BENCH_DATA = b"benchmark test data for multihash operations" * 100
    
    @pytest.mark.benchmark
    def test_bench_sum_sha256(benchmark):
        benchmark(sum, BENCH_DATA, Func.sha2_256)
    
    @pytest.mark.benchmark
    def test_bench_sum_sha512(benchmark):
        benchmark(sum, BENCH_DATA, Func.sha2_512)
    
    @pytest.mark.benchmark
    def test_bench_sum_blake3(benchmark):
        benchmark(sum, BENCH_DATA, Func.blake3)
    
    @pytest.mark.benchmark
    @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)
    
    @pytest.mark.benchmark
    def test_bench_encode(benchmark):
        digest = sum(BENCH_DATA, Func.sha2_256)
        benchmark(digest.encode)
    
    @pytest.mark.benchmark
    def test_bench_decode(benchmark):
        encoded = sum(BENCH_DATA, Func.sha2_256).encode()
        benchmark(decode, encoded)

Related

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions