<script src="https://unpkg.com/fflate"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/pako/2.0.3/pako.min.js"></script>
<!--<script src="https://cdn.jsdelivr.net/npm/zlibjs@0.3.1/bin/zlib_and_gzip.min.js"></script>-->
<script src="https://cdn.jsdelivr.net/npm/zlibjs@0.3.1/bin/rawdeflate.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/zlibjs@0.3.1/bin/rawinflate.min.js"></script>
var enc = new TextEncoder();
var a = new Uint8Array([100 * 1024]);
for (var i; i < 100 * 1024; i++)
a[i] = Math.floor(Math.random() * 256)
var b = enc.encode('The quick brown fox jumps over the lazy dog')
//var ca = pako.deflate(a)
//var cb = pako.deflate(b)
var deflate = new Zlib.RawDeflate(a);
var ca = deflate.compress();
var deflate = new Zlib.RawDeflate(b);
var cb = deflate.compress();
console.log(cb)
pako.inflateRaw(ca)
pako.inflateRaw(cb)
pako.deflateRaw(a)
pako.deflateRaw(b)
fflate.decompressSync(ca);
fflate.decompressSync(cb);
fflate.gzipSync(a)
fflate.gzipSync(b)
var deflate = new Zlib.RawDeflate(a);
var compressed = deflate.compress();
// compressed = Array.<number> or Uint8Array
var inflate = new Zlib.RawInflate(ca);
var plain = inflate.decompress();
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
inflate pako a | |
inflate pako b | |
deflate pako a | |
deflate pako b | |
unzip fflate a | |
unzip fflate b | |
zip fflate a | |
zip fflate b | |
zlibjs Raw Deflate compress | |
zlibjs Raw Deflate decompress |
Test name | Executions per second |
---|---|
inflate pako a | 6794.7 Ops/sec |
inflate pako b | 7346.3 Ops/sec |
deflate pako a | 1421.5 Ops/sec |
deflate pako b | 1431.3 Ops/sec |
unzip fflate a | 16358.0 Ops/sec |
unzip fflate b | 3100.9 Ops/sec |
zip fflate a | 6483.5 Ops/sec |
zip fflate b | 5211.4 Ops/sec |
zlibjs Raw Deflate compress | 3948.9 Ops/sec |
zlibjs Raw Deflate decompress | 22371.1 Ops/sec |
Measuring the performance of JavaScript libraries is crucial for developers to choose the best library for their specific needs.
The provided benchmark tests the compression and decompression performance of three JavaScript libraries: pako, fflate, and Zlib.js. Here's a breakdown of each library and its purpose:
The benchmark tests the following scenarios:
inflate()
and deflate()
inflate()
and compress()
inflate()
and deflate()
unzip fflate a
(decompressing data using fflate)inflate pako b
(inflating compressed data using pako)The results show that:
unzip fflate a
test shows that fflate's decompression speed is similar to pako's compression speed.In conclusion, if you need fast compression and decompression performance, fflate might be the best choice. However, if you prioritize simplicity and lightweightness, pako might be a better fit. For developers who already know the Zlib library, using Zlib.js can provide a familiar API while still leveraging the performance benefits of the original C library.
Keep in mind that this benchmark only tests specific use cases, and there may be other scenarios where other libraries perform better or worse.