Skip to content

No benchmark tests #71

Description

@sumanjeet0012

There are no benchmark tests. Go has BenchmarkIdentityCheck which compares the performance of Cid.Prefix() vs multihash.Decode() for checking hash types.

Proposed Solution

Add tests/test_benchmarks.py:

import pytest
import hashlib
import multihash
from cid import CIDv1, Prefix

@pytest.fixture
def bench_cid():
    data = b"benchmark data" * 100
    digest = hashlib.sha256(data).digest()
    mh_bytes = multihash.encode(digest, "sha2-256")
    return CIDv1("raw", mh_bytes)

@pytest.mark.benchmark
def test_bench_cid_buffer(benchmark, bench_cid):
    benchmark(lambda: bench_cid.buffer)

@pytest.mark.benchmark
def test_bench_cid_encode(benchmark, bench_cid):
    benchmark(bench_cid.encode)

@pytest.mark.benchmark
def test_bench_cid_prefix(benchmark, bench_cid):
    benchmark(bench_cid.prefix)

@pytest.mark.benchmark
def test_bench_prefix_sum(benchmark):
    prefix = Prefix.v1(codec="raw", mh_type="sha2-256")
    data = b"benchmark data" * 100
    benchmark(prefix.sum, data)

@pytest.mark.benchmark
def test_bench_make_cid(benchmark, bench_cid):
    cid_str = str(bench_cid)
    from cid import make_cid
    benchmark(make_cid, cid_str)

Related

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