Compression Algorithm Comparison

Benchmark gzip at three levels, zlib deflate, Brotli and LZ4 on your own data in the browser, with sizes, ratios and timing percentiles.

The interactive tool loads here when JavaScript runs.

About this tool

What is the Compression Comparison?

The Compression Comparison runs six real codec settings over the same input and puts the results in one table: gzip at levels 1, 6 and 9, zlib deflate at level 6, Brotli at quality 11 and LZ4. For each it reports compressed size, ratio (original divided by compressed, so 4.00:1 means a quarter of the size), space saved and the time to compress and decompress.

Choose sample text, JSON, CSV or XML, or paste your own data, then pick how many iterations to run and whether to summarise times as an average or as the p50, p95 or p99 percentile. Every run decompresses the output and checks it round-trips, so the timings cover real work.

Timings come from your browser's JavaScript and WebAssembly engines, so they are useful for comparing codecs against each other on this machine, not for predicting native zlib or server throughput. If Brotli's WebAssembly module cannot load, its row is skipped with a note rather than estimated.

  • Real gzip, zlib, Brotli (WebAssembly) and LZ4 implementations
  • Ratio shown as original:compressed plus space saved
  • Average, p50, p95 and p99 timing with nearest-rank percentiles
  • Round-trip check on every codec
  • Sample text, JSON, CSV and XML, or your own data
Read the guide: Gzip vs Brotli vs LZ4: Choosing a Compression Algorithm

Updated

How to use the Compression Comparison

  1. Pick a Data Type for built-in sample data, or Custom and paste your own into Data to Compress.
  2. Choose Iterations. More runs give steadier timings for small inputs.
  3. Choose the Statistical Metric for times: Average, P50, P95 or P99.
  4. Click Compare Algorithms and read the summary cards and the Detailed Comparison Results table.
  5. Change the data or settings and click Run Again to compare.

Worked example

Repetitive JSON

Input

{"id":1,"name":"Ada"} repeated 50 times (1,050 bytes)

Output

Gzip (Level 6): 50 bytes, 21.00:1 (95.2%)
Deflate (zlib): 38 bytes, 27.63:1 (96.4%)
LZ4: 50 bytes, 21.00:1 (95.2%)

Gzip and zlib carry the same DEFLATE data, so they differ by exactly the 12 bytes of wrapper overhead. Brotli lands around 40 bytes on this input.

Background and insight

Compression is a trade-off between three numbers: output size, compression speed and decompression speed. DEFLATE-based gzip is the universal baseline. Brotli usually produces smaller output, especially for web text, but at its highest quality it is far slower to compress. LZ4 is built to be very fast on both sides and accepts larger output. Which matters depends on whether you compress once and serve many times (static assets) or compress every request.

Ratios are easy to misread. This tool reports the ratio as original over compressed, the convention used by most benchmarks, alongside space saved as a percentage of the original. A file that goes from 1,050 to 50 bytes has a ratio of 21.00:1 and saves 95.2%. Going from 50% to 75% saved halves the output again, which is why small percentage differences at the top end matter.

Timing small inputs in a browser is noisy: garbage collection, JIT warm-up and timer resolution all show up. That is why the tool runs several iterations and offers percentiles, computed with the nearest-rank method. Use p50 for typical cost and p95 or p99 to see how bad the slow runs are. For a broader view of formats themselves (JSON, XML, Protocol Buffers), see the Data Format Comparison guide.

Common use cases

  • Choosing HTTP compression

    Measure how much Brotli saves over gzip on your real API responses or HTML before enabling it on a server or CDN.

  • Picking a codec for storage or queues

    See whether LZ4's speed is worth its larger output for logs, cache entries or message payloads.

  • Tuning compression levels

    Compare gzip levels 1, 6 and 9 to see how much extra size you buy with slower compression.

  • Teaching compression trade-offs

    Show how text, JSON, CSV and XML compress differently because of how much repetition they contain.

Tips and limitations

  • Use realistic data. Lorem ipsum and repeated JSON compress far better than most production payloads.
  • Inputs under a few hundred bytes are dominated by headers and dictionary effects, so ratios there tell you little.
  • Brotli at quality 11 is meant for build-time compression. On-the-fly servers usually run quality 4 to 6, which is faster and somewhat larger.
  • Sizes are UTF-8 bytes of the input, so non-English text starts larger than its character count.
  • Compare times only within one run on one machine. Another browser or a busy laptop will shift every number.

Sources and further reading

  1. RFC 1951: DEFLATE Compressed Data Format Specification version 1.3, Internet Engineering Task Force. The method inside gzip, the baseline
  2. RFC 7932: Brotli Compressed Data Format, Internet Engineering Task Force. Brotli's format and quality levels
  3. LZ4: Extremely Fast Compression algorithm, LZ4 project. Reference implementation and speed figures
  4. Performance: now() method, MDN Web Docs. The browser timer and its reduced resolution, which make small timings noisy

Frequently asked questions

Which compresses better, gzip or Brotli?

Brotli usually produces smaller output on text, often noticeably smaller on HTML, CSS and JavaScript thanks to its built-in dictionary. The difference depends on the data, so paste a real response into this tool and compare the Compressed Size column for Gzip (Best) and Brotli.

How is the compression ratio calculated?

Ratio is original size divided by compressed size, so 1,000 bytes compressed to 250 is 4.00:1. Space saved is (original minus compressed) divided by original, 75% in that case. A higher ratio and a higher percentage are both better.

Why is LZ4 output larger than gzip?

LZ4 skips the entropy coding step that gzip and Brotli use and keeps its matching simple, which is what makes it very fast. The price is a lower ratio. It is the right choice when CPU time matters more than bytes, such as in databases and caches.

Are these browser timings accurate?

They are real measurements of the JavaScript and WebAssembly codecs in your browser, taken with performance.now(). They are good for comparing codecs on the same machine and data, but native command-line tools and server libraries run faster, so do not treat them as absolute throughput.

What do the p95 and p99 options mean?

They are percentiles of the per-iteration times. p95 is the time that 95% of runs finished within, using the nearest-rank method. With 10 iterations p95 and p99 are both the slowest run, so use 50 or 100 iterations when tail times matter.

Why is Deflate exactly 12 bytes smaller than gzip?

Both contain the same DEFLATE stream at the same level. gzip wraps it in 18 bytes of header and trailer, zlib in 6, so the difference is always 12 bytes regardless of input.

Is there an in-depth guide to the Compression Comparison?

Yes. “Gzip vs Brotli vs LZ4: Choosing a Compression Algorithm” covers the background, how it works, common pitfalls and worked examples. Read the full guide.