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
-
Install pytest-benchmark as a dev dependency.
-
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
There are no benchmark tests for encode/decode operations. go-multibase includes
BenchmarkEncode,BenchmarkDecode, andBenchmarkRoundTripfor 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:
Proposed Solution
Install
pytest-benchmarkas a dev dependency.Create
tests/test_benchmarks.py:Related
multibase_test.goBenchmarkEncode,BenchmarkDecode,BenchmarkRoundTrip