Skip to content

No benchmark tests for encode/decode operations #42

Description

@sumanjeet0012

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

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