µZ (microz) is a minimalistic implementation of some compression schemes, namely:
- Deflate (RFC1951)
- ZLib (RFC1950)
- GZip (RFC1952)
- 2025-11-30: First pass. Supports decompressing deflate, zlib and gzip formats.
- Decompression:
- Deflate
- Zlib
- GZip
- Compression:
- Deflate
- Zlib
- GZip
decompress :: (src: string, size_hint := 0) -> string, ReturnStatus-- accepts a compressed string and an optional size hint. Returns a decompressed string on success, and a status. Will automatically try to determine which kind of compression is used.zlib_decompress :: (src_: string, size_hint := 0) -> string, ReturnStatus-- Accepts a compressed zlib string and optional size hint. Returns a decompressed string on success, and a status.zlib_decompress :: (src: []u8, size_hint := 0) -> []u8, ReturnStatus-- Same as above, but works on a[]u8instead of a string.gzip_decompress :: (src_: string, size_hint := 0) -> string, ReturnStatus-- Accepts a compressed gzip string and optional size hint. Returns a decompressed string on success, and a status.deflate_inflate_stream :: (in: *string, window_size: u32, out: *OutputBuffer) -> ReturnStatus-- Accepts a pointer to a Deflate string, a window size, and an OutputBuffer. Moves the pointer of the input string to the end of the DEFLATE stream. On success, the OuputBuffer will contain valid output.
Included are benchmarks based on the Silesia Compression Corpous, for comparing this library to zlib (the library) and libdeflate.
Your milage will vary. Build and run all with scripts/benchmark.sh. Get the Silesia Corpus and compress it with
scripts/getbenchmarkdata.sh.
The below table is from a laptop running an Intel Core Ultra 7 165H CPU on Linux.
| File | microz MB/s | zlib MB/s | libdeflate MB/s | microz vs zlib | microz vs libdeflate |
|---|---|---|---|---|---|
| dickens | 111.73 | 124.80 | 320.38 | 89.5% | 34.9% |
| mozilla | 141.59 | 161.98 | 377.75 | 87.4% | 37.5% |
| mr | 146.29 | 169.26 | 442.16 | 86.4% | 33.1% |
| nci | 316.82 | 368.26 | 459.72 | 86.0% | 68.9% |
| ooffice | 115.04 | 125.71 | 351.34 | 91.5% | 32.7% |
| osdb | 171.76 | 169.37 | 660.91 | 101.4% | 26.0% |
| reymont | 180.58 | 201.12 | 725.08 | 89.8% | 24.9% |
| samba | 182.35 | 204.97 | 663.74 | 88.9% | 27.5% |
| sao | 115.27 | 114.49 | 327.84 | 100.7% | 35.2% |
| webster | 143.77 | 168.43 | 488.54 | 85.3% | 29.4% |
| xml | 268.30 | 372.42 | 880.57 | 72.0% | 30.5% |
| x-ray | 93.97 | 108.12 | 283.16 | 86.9% | 33.2% |
| Total | 156.32 | 177.06 | 441.18 | 88.3% | 35.4% |
Currently no GZip benchmarking, but since the overwhelming majority of time is spent handling DEFLATE, this they tell the story for GZip pretty well too.
Smári McCarthy smari@yaxic.org
Released under the terms of the Apache 2.0 license.