multiformats / multiformats/py-multibase

No benchmark tests for encode/decode operations

Open Beginner friendly
#42 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
25
Forks
9
PR merge metrics
No merged PRs in 30d

Description

There are no benchmark tests for encode/decode operations. go-multibase includes BenchmarkEncode, BenchmarkDecode, and BenchmarkRoundTrip for every encoding, which help catch performance regressions.

Problem

The test suite has functional tests but zero benchmarks. Operations like base58 encoding (which involves big-integer arithmetic) and base256emoji encoding (which involves UTF-8 encoding) have no performance baseline.

go-multibase benchmarks every encoding:

func BenchmarkEncode(b *testing.B) {
    for _, name := range benchmarkCodecs {
        b.Run(name, func(b *testing.B) {
            base := Encodings[name]
            for i := 0; i < b.N; i++ {
                Encode(base, benchmarkBuf[:])
            }
        })
    }
}
Proposed Solution
  1. Install pytest-benchmark as a dev dependency.

  2. Create tests/test_benchmarks.py:

    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)
    
Related

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Create tests/test_benchmarks.py using pytest-benchmark and the existing multibase.encode, decode, and ENCODINGS APIs. Add parametrized encode, decode, and round-trip benchmarks with the proposed benchmark data, and install pytest-benchmark as a development dependency. Done means every encoding has all three benchmark cases and the benchmark tests run successfully.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
performance, testing
Issue type
Feature
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
75/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.