<script src="https://unpkg.com/fflate"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/pako/2.0.3/pako.es5.min.js"></script>
const enc = new TextEncoder();
var a = new Uint8Array([Array(1000000).keys()]);
var b = enc.encode('The quick brown fox jumps over the lazy dog')
var ca = pako.deflate(a)
var cb = pako.deflate(b)
pako.inflate(ca)
pako.inflate(cb)
pako.deflate(a)
pako.deflate(b)
fflate.unzlibSync(ca);
fflate.unzlibSync(cb);
fflate.zlibSync(a)
fflate.zlibSync(b)
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
unzip pako a | |
unzip pako b | |
zip pako a | |
zip pako b | |
unzip fflate a | |
unzip fflate b | |
zip fflate a | |
zip fflate b |
Test name | Executions per second |
---|---|
unzip pako a | 328.2 Ops/sec |
unzip pako b | 60642.9 Ops/sec |
zip pako a | 62.6 Ops/sec |
zip pako b | 5745.0 Ops/sec |
unzip fflate a | 288.8 Ops/sec |
unzip fflate b | 7756.3 Ops/sec |
zip fflate a | 54.0 Ops/sec |
zip fflate b | 16311.2 Ops/sec |
Let's break down the benchmark and its results.
Benchmark Definition
The test compares the performance of two libraries: pako
(also known as pako.js
) and fflate
. Both libraries are designed to compress and decompress data using algorithms similar to zlib. The test focuses on three main operations:
zip
): Compressing a string or array using either pako.deflate()
or fflate.zlibSync()
.unzip
): Decompressing a previously compressed data using either pako.inflate()
or fflate.unzlibSync()
.Options Compared
The test compares the performance of two options for each operation:
pako.deflate()
and fflate.zlibSync()
: These are the compression algorithms used by pako
and fflate
, respectively. Both libraries implement a variant of the DEFLATE algorithm, but with some differences in implementation details.pako.inflate()
and fflate.unzlibSync()
: These are the decompression algorithms used by pako
and fflate
, respectively. Again, both libraries implement a variant of the DEFLATE algorithm, but with different implementation details.Pros and Cons
Here's a brief summary of the pros and cons of each approach:
Library Usage
Both pako
and fflate
are JavaScript libraries designed to provide a convenient interface for working with DEFLATE data compression. They share similarities in their implementation but have some key differences:
Special JS Features
The benchmark uses some special JavaScript features:
new Uint8Array([...Array(1000000).keys()])
: Creates a large array of integers using the spread operator.const enc = new TextEncoder();
and var b = enc.encode('...')
: Uses the TextEncoder
API to encode a string as a sequence of bytes.Other Alternatives
If you're interested in exploring alternative compression libraries, here are some options:
Keep in mind that each alternative has its own strengths and weaknesses, so it's essential to evaluate the trade-offs based on your specific requirements.