Skip to main content

Benchmarks

The suite in benchmarks/EngramBenchmark canonicalizes and fingerprints an object holding an array of Items records (a name, a decimal price, two tags, a boolean and an id), from a parsed JsonElement and from raw UTF-8 bytes.

BenchmarkWhat it measures
CanonicalizeCanonicalize(JsonElement): the canonical text (baseline)
HashHash(JsonElement): canonical form, UTF-8 encoding and SHA-256
HashFromUtf8Hash(ReadOnlySpan<byte>): the same, parsing included

Results​

BenchmarkDotNet 0.15.8, ShortRun (3 warmups, 3 iterations), .NET 10.0.14, Apple M5 Pro, macOS.

MethodItemsMeanAllocated
Canonicalize104.10 µs16.85 KB
Hash104.50 µs17.77 KB
HashFromUtf8107.50 µs17.84 KB
Canonicalize1000446.07 µs1627.18 KB
Hash1000479.36 µs1699.59 KB
HashFromUtf81000773.53 µs1699.66 KB

Hashing adds about 10% to canonicalization; parsing the bytes adds about 70%. Time and allocations grow linearly with the document. The 1.0 implementation favours exactness over speed (it builds a string and sorts members in lists), so allocations are the first thing to improve.

Running the benchmarks​

dotnet run --project benchmarks/EngramBenchmark -c Release
# a quick, less precise run
dotnet run --project benchmarks/EngramBenchmark -c Release -- --filter '*' --job short