A compression benchmark, right in your browser.
kokyu is deflate, zlib, gzip and zip for every JavaScript runtime, in TypeScript with no dependencies. Pick a sample, or a file or folder of your own, and kokyu compresses it, decompresses it again and times both. fflate, one of the most downloaded compression libraries on npm, runs the same job beside it, so the numbers have something to stand against. Nothing you pick leaves your browser.
Pick an input and press Run. Nothing leaves your browser.
| Measure | kokyu | fflate 0.8.3 | Difference |
|---|---|---|---|
| Output | |||
| Compress | |||
| Decompress | |||
| Check |
The calls behind it
What each run calls, for the format you pick. Both libraries are called the way their own docs show, at the level you choose.
kokyu
import { gzip, gunzip, gzipAsync, gunzipAsync } from 'kokyu'
const packed = gzip(data, { level: 6 })
const back = gunzip(packed)
// Off the main thread, in kokyu's pool of workers
const packedAsync = await gzipAsync(data, { level: 6 })
const backAsync = await gunzipAsync(packedAsync)fflate
import { gzipSync, gunzipSync, gzip, gunzip } from 'fflate'
const packed = gzipSync(data, { level: 6 })
const back = gunzipSync(packed)
// Off the main thread, in a worker started for the call
gzip(data, { level: 6 }, (err, packedAsync) => {
gunzip(packedAsync, (err, backAsync) => {})
})kokyu
import { zlib, unzlib, zlibAsync, unzlibAsync } from 'kokyu'
const packed = zlib(data, { level: 6 })
const back = unzlib(packed)
// Off the main thread, in kokyu's pool of workers
const packedAsync = await zlibAsync(data, { level: 6 })
const backAsync = await unzlibAsync(packedAsync)fflate
import { zlibSync, unzlibSync, zlib, unzlib } from 'fflate'
const packed = zlibSync(data, { level: 6 })
const back = unzlibSync(packed)
// Off the main thread, in a worker started for the call
zlib(data, { level: 6 }, (err, packedAsync) => {
unzlib(packedAsync, (err, backAsync) => {})
})kokyu
import { deflate, inflate, deflateAsync, inflateAsync } from 'kokyu'
const packed = deflate(data, { level: 6 })
const back = inflate(packed)
// Off the main thread, in kokyu's pool of workers
const packedAsync = await deflateAsync(data, { level: 6 })
const backAsync = await inflateAsync(packedAsync)fflate
import { deflateSync, inflateSync, deflate, inflate } from 'fflate'
const packed = deflateSync(data, { level: 6 })
const back = inflateSync(packed)
// Off the main thread, in a worker started for the call
deflate(data, { level: 6 }, (err, packedAsync) => {
inflate(packedAsync, (err, backAsync) => {})
})kokyu
import { zip, unzip, zipAsync, unzipAsync } from 'kokyu'
const archive = zip({ input: data }, { level: 6 })
const back = unzip(archive).input
// Off the main thread, in kokyu's pool of workers
const archiveAsync = await zipAsync({ input: data }, { level: 6 })
const backAsync = (await unzipAsync(archiveAsync)).inputfflate
import { zipSync, unzipSync, zip, unzip } from 'fflate'
const archive = zipSync({ input: data }, { level: 6 })
const back = unzipSync(archive).input
// Off the main thread, in workers started for the call
zip({ input: data }, { level: 6 }, (err, archiveAsync) => {
unzip(archiveAsync, (err, files) => {})
})How it's measured
- Both libraries get the same bytes, format and level. The samples come from one seed, so every visit gets the same ones.
- A folder goes into zip as it is, one entry per file at its path in the folder. gzip, zlib and raw deflate take a single stream, so for them its files are joined end to end.
- There's no size limit but your device's memory. A run holds the input, every output and what they decode to, so it needs a few times the input's size, and since each call runs at least four times, big inputs take a while.
- Each time is the median of 3 to 15 rounds. In a round each library runs for at least 25 ms, so even a coarse browser timer reads it closely, and the one that goes first swaps every round.
- For decompression, each library decodes every output, kokyu's and fflate's, so both decode the same bytes.
- Every output is decoded by both libraries and compared with the input byte for byte. If one doesn't match, the check row says so.
- Sync runs both libraries' one-shot calls in a worker, so the page stays responsive while they work.
- Async calls each library's own async API from this page. kokyu runs inputs under 16 KB right away and keeps a pool of workers, while fflate starts a worker for every call, which is most of the difference on small inputs.
- The numbers are your device's own, and other busy tabs make them noisier. A KB here is 1,024 bytes, and an MB 1,024 KB.
About fflate
fflate 0.8.3 is by 101arrowz, under the MIT license. Its source is at github.com/101arrowz/fflate.