BENCHMARKS · HASHING & IDS
Cryptographic vs non-cryptographic hashing; Guid v4 vs v7. Suite and raw reports: github.com/gdhami-net/dotnet-benchmarks.
HashPayload
Hash the same payload: cryptographic SHA-256 vs the non-cryptographic XxHash family — pick by threat model, know the cost.
TAKEAWAY Pick by threat model, not speed: content addressing and checksums can take XxHash3's 10x win; anything security-relevant stays SHA-256 - which is already hardware-fast.
In this run: XxHash3_hash is fastest — 13.7× faster than the baseline.
In this run: XxHash3_hash is fastest — 13.7× faster than the baseline.
RESULTS — 1024
| method | net9.0 | net10.0 | ratio | allocated | Δ net10.0 |
|---|---|---|---|---|---|
| Sha256 baseline | 325 ns ±6 ns | 320 ns ±4 ns | 1.00× | 56 B | -1% |
| XxHash64_hash | 55 ns ±2 ns | 54 ns ±0 ns | 0.17× | 32 B | -2% |
| XxHash3_hash | 23 ns ±2 ns | 23 ns ±0 ns | 0.07× | 32 B | -0% |
RATIO VS BASELINE — 1024 · net10.0
RESULTS — 1048576
| method | net9.0 | net10.0 | ratio | allocated | Δ net10.0 |
|---|---|---|---|---|---|
| Sha256 baseline | 213.2 µs ±2.5 µs | 209.6 µs ±839 ns | 1.00× | 56 B | -2% |
| XxHash64_hash | 45.9 µs ±45 ns | 47.1 µs ±717 ns | 0.22× | 32 B | +3% |
| XxHash3_hash | 18.6 µs ±37 ns | 17.5 µs ±133 ns | 0.08× | 32 B | -6% |
RATIO VS BASELINE — 1048576 · net10.0
SCALING · net10.0 · MEAN TIME BY INPUT SIZE (LOG)
Sha256XxHash64_hashXxHash3_hash
THE LEDGER · SAME WORKLOAD ACROSS RELEASES (LOG)
Sha256XxHash64_hashXxHash3_hash
THE CODE BEING MEASURED
Sha256 — what this measures
SHA-256 — cryptographic, hardware-accelerated on modern CPUs.
[Benchmark (Baseline)]
public byte[] Sha256()
=> SHA256.HashData(_payload);XxHash64_hash — what this measures
XxHash64 — fast non-cryptographic checksum (System.IO.Hashing).
[Benchmark]
public byte[] XxHash64_hash()
=> XxHash64.Hash(_payload);XxHash3_hash — what this measures
XxHash3 — the newer, usually faster member of the family.
[Benchmark]
public byte[] XxHash3_hash()
=> XxHash3.Hash(_payload);MakeIds
Make 1,000 ids: random Guid v4 vs .NET 9's time-ordered v7 — v7 exists so your database index stops fragmenting.
TAKEAWAY Guid.CreateVersion7 costs a whisker more to create and saves you from fragmented clustered indexes forever. For database keys, v7 is the new default.
In this run: Guid_v4 is fastest (it is the baseline).
In this run: Guid_v4 is fastest (it is the baseline).
RESULTS
| method | net9.0 | net10.0 | ratio | allocated | Δ net10.0 |
|---|---|---|---|---|---|
| Guid_v4 baseline | 35.3 µs ±534 ns | 34.7 µs ±214 ns | 1.00× | — | -2% |
| Guid_v7 | 60.2 µs ±752 ns | 58.4 µs ±334 ns | 1.68× | — | -3% |
RATIO VS BASELINE · net10.0
THE LEDGER · SAME WORKLOAD ACROSS RELEASES (LOG)
Guid_v4Guid_v7
THE CODE BEING MEASURED
Guid_v4 — what this measures
Guid.NewGuid — random v4.
[Benchmark (Baseline)]
public Guid Guid_v4()
{
var g = Guid.Empty;
for (var i = 0; i < 1_000; i++) g = Guid.NewGuid();
return g;
}Guid_v7 — what this measures
Guid.CreateVersion7 (.NET 9+) — time-ordered, index-friendly.
[Benchmark]
public Guid Guid_v7()
{
var g = Guid.Empty;
for (var i = 0; i < 1_000; i++) g = Guid.CreateVersion7();
return g;
}speed vs allocation
Fast is one axis. What it costs the GC is the other.
Sha256XxHash64_hashXxHash3_hashGuid_v4Guid_v7