Skip to content

Benchmarks

This page presents detailed benchmark results for all compressionz codecs.

PropertyValue
PlatformmacOS (Darwin) on Apple Silicon (aarch64)
BuildReleaseFast optimization
Iterations20 benchmark runs (3 warmup)
DataMixed-pattern: repetitive text, sequential bytes, varied data
CodecCompressDecompressRatioRecommendation
LZ4 Raw36.6 GB/s8.1 GB/s99.5%Maximum speed
Snappy31.6 GB/s9.2 GB/s95.3%Real-time
Zstd12.0 GB/s11.6 GB/s99.9%Best overall
LZ4 Frame4.8 GB/s3.8 GB/s99.3%File storage
Gzip2.4 GB/s2.4 GB/s99.2%Compatibility
Brotli1.3 GB/s1.9 GB/s99.9%Static assets
CodecLevelRatioSizeCompressDecompress
LZ4 Framefast41.2%588 B9.2 µs5.1 µs
LZ4 Framedefault41.2%588 B8.9 µs4.8 µs
LZ4 Rawdefault43.9%561 B3.8 µs1.7 µs
Snappydefault42.1%579 B7.2 µs0.1 µs
Zstdfast43.0%570 B13.6 µs0.7 µs
Zstddefault43.0%570 B10.4 µs0.7 µs
Zstdbest43.0%570 B177.9 µs0.9 µs
Gzipfast40.0%600 B20.3 µs6.7 µs
Gzipdefault40.0%600 B24.3 µs5.6 µs
Gzipbest40.1%599 B31.6 µs5.4 µs
Brotlifast41.8%582 B24.1 µs6.3 µs
Brotlidefault42.0%580 B26.1 µs6.1 µs
Brotlibest44.9%551 B1.6 ms10.0 µs

1 KB Winner: Brotli best achieves highest ratio (44.9%), but Zstd offers best speed/ratio balance.

CodecLevelRatioSizeCompressDecompress
LZ4 Framefast93.6%641 B11.4 µs6.2 µs
LZ4 Framedefault93.6%641 B10.1 µs6.4 µs
LZ4 Rawdefault93.9%614 B8.9 µs2.7 µs
Snappydefault89.8%1,018 B10.0 µs2.7 µs
Zstdfast94.1%595 B16.9 µs3.1 µs
Zstddefault94.1%595 B15.5 µs3.0 µs
Zstdbest94.1%592 B60.7 µs3.6 µs
Gzipfast92.9%712 B26.0 µs10.4 µs
Gzipdefault93.1%695 B36.4 µs12.1 µs
Gzipbest93.1%693 B36.6 µs12.7 µs
Brotlifast94.0%604 B33.1 µs22.3 µs
Brotlidefault94.1%595 B40.1 µs23.1 µs
Brotlibest94.7%529 B978.5 µs29.2 µs

10 KB Winner: Zstd achieves best ratio (94.1%) with fast compression.

CodecLevelRatioSizeCompressDecompress
LZ4 Framefast99.0%1.0 KB25.0 µs29.7 µs
LZ4 Framedefault99.0%1.0 KB23.0 µs30.1 µs
LZ4 Rawdefault99.0%968 B11.6 µs11.7 µs
Snappydefault94.8%5.1 KB10.0 µs11.6 µs
Zstdfast99.4%599 B19.7 µs9.9 µs
Zstddefault99.4%599 B19.1 µs10.5 µs
Zstdbest99.4%596 B176.2 µs10.8 µs
Gzipfast98.6%1.4 KB63.5 µs66.0 µs
Gzipdefault98.9%1.0 KB166.3 µs62.4 µs
Gzipbest98.9%1.0 KB311.7 µs128.8 µs
Brotlifast99.4%608 B60.5 µs74.5 µs
Brotlidefault99.4%598 B81.6 µs76.4 µs
Brotlibest99.5%539 B3.9 ms89.0 µs

100 KB Winner: Zstd dominates with 99.4% ratio and fastest decompression.

CodecLevelRatioSizeCompressDecompress
LZ4 Framefast99.3%6.9 KB208.9 µs270.4 µs
LZ4 Framedefault99.3%6.9 KB214.8 µs263.9 µs
LZ4 Rawdefault99.5%4.4 KB27.3 µs123.2 µs
Snappydefault95.3%46.4 KB31.7 µs108.3 µs
Zstdfast99.9%684 B82.3 µs87.5 µs
Zstddefault99.9%684 B83.4 µs86.5 µs
Zstdbest99.9%677 B783.4 µs82.8 µs
Gzipfast99.2%7.5 KB408.9 µs412.3 µs
Gzipdefault99.6%4.3 KB1.4 ms353.4 µs
Gzipbest99.6%4.3 KB1.4 ms347.3 µs
Brotlifast99.9%616 B751.1 µs537.1 µs
Brotlidefault99.9%608 B767.1 µs564.9 µs
Brotlibest99.9%535 B11.6 ms678.1 µs

1 MB Winner: Zstd achieves 99.9% ratio at 12 GB/s — unbeatable balance.

LZ4 Raw ████████████████████████████████████████ 36.6 GB/s
Snappy ██████████████████████████████████ 31.6 GB/s
Zstd █████████████ 12.0 GB/s
LZ4 Frame █████ 4.8 GB/s
Gzip ███ 2.4 GB/s
Brotli █ 1.3 GB/s
Zstd █████████████ 11.6 GB/s
Snappy ██████████ 9.2 GB/s
LZ4 Raw █████████ 8.1 GB/s
LZ4 Frame ████ 3.8 GB/s
Gzip ███ 2.4 GB/s
Brotli ██ 1.9 GB/s
Zstd ██████████████████████████████████████████████ 99.9%
Brotli ██████████████████████████████████████████████ 99.9%
Gzip █████████████████████████████████████████████ 99.6%
LZ4 Raw █████████████████████████████████████████████ 99.5%
LZ4 Frame ████████████████████████████████████████████ 99.3%
Snappy ███████████████████████████████████████ 95.3%

LZ4 Raw — 36.6 GB/s

const compressed = try cz.compress(.lz4_raw, data, allocator);
// Requires: .expected_size for decompression

Zstd (best level) — 12.1 GB/s

const compressed = try cz.compressWithOptions(.zstd, data, allocator, .{
.level = .best,
});
// Slow to compress, fast to decompress

Brotli (best level) — 99.9%+

const compressed = try cz.compressWithOptions(.brotli, data, allocator, .{
.level = .best,
});
// 535 bytes from 1 MB (test data)

Zstd (default) — 12 GB/s compress, 11.6 GB/s decompress, 99.9% ratio

const compressed = try cz.compress(.zstd, data, allocator);
CodecCompressionDecompression
LZ4 Raw984.8 KB976.6 KB
LZ4 Frame987.8 KB1.0 MB
Snappy1.1 MB976.6 KB
Zstd981.0 KB976.6 KB
Gzip984.4 KB2.8 MB
Brotli977.4 KB1.8 MB

Most Memory-Efficient: Zstd and LZ4 Raw use ~input size only.

Terminal window
# Run with optimizations (required for accurate results)
zig build bench -Doptimize=ReleaseFast
# Output includes:
# - Per-codec results at each data size
# - Throughput in MB/s and GB/s
# - Memory usage
# - CPU time

Mixed-pattern data designed for realistic compression:

25% — Repetitive text ("The quick brown fox...")
25% — Sequential bytes with variations
25% — Repetitive text (repeated)
25% — Varied pseudorandom data
  • Wall time: std.time.Timer
  • CPU time: getrusage() system call
  • Memory: Custom counting allocator
  • Iterations: 20 measured runs after 3 warmup

Results may vary based on:

  • CPU architecture and generation
  • Memory speed and cache sizes
  • Operating system
  • Data characteristics

Run benchmarks on your target hardware for accurate numbers.