📜 ⬆️ ⬇️

Quick javascript gzip for browser and node.js

Recently, the pako project has appeared, this is the port to javascript of the well-known library for compression and decompression of data - zlib .

Very curious test result.

On the v8 year old engine, the speed of the calculations was only one and a half times lower than the original library written in C. And in the more recent node, the gap was reduced to 1.2-1.3 times. Here are the published benchmarks:

node v0.10.26, 1mb sample:
')
deflate-dankogai x 4.74 ops / sec ± 0.68% (15 runs sampled)
deflate-gildas x 4.61 ops / sec ± 1.73% (15 runs sampled)
deflate-imaya x 3.10 ops / sec ± 3.73% (11 runs sampled)
! deflate-pako x 7.11 ops / sec ± 0.26% (21 runs sampled)
deflate-pako-untyped x 4.34 ops / sec ± 1.35% (14 runs sampled)
deflate-zlib x 14.34 ops / sec ± 2.90% (68 runs sampled)
inflate-dankogai x 31.29 ops / sec ± 0.72% (56 runs sampled)
inflate-imaya x 30.49 ops / sec ± 0.84% ​​(53 runs sampled)
! inflate-pako x 70.00 ops / sec ± 1.60% (71 runs sampled)
inflate-pako-untyped x 17.67 ops / sec ± 1.27% (33 runs sampled)
inflate-zlib x 70.82 ops / sec ± 1.69% (81 runs sampled)


node v0.11.11, 1mb sample:

deflate-dankogai x 5.61 ops / sec ± 0.30% (17 runs sampled)
deflate-gildas x 4.97 ops / sec ± 5.68% (16 runs sampled)
deflate-imaya x 3.53 ops / sec ± 4.19% (12 runs sampled)
! deflate-pako x 11.52 ops / sec ± 0.23% (32 runs sampled)
deflate-pako-untyped x 5.12 ops / sec ± 1.44% (17 runs sampled)
deflate-zlib x 14.33 ops / sec ± 3.34% (63 runs sampled)
inflate-dankogai x 42.96 ops / sec ± 0.19% (57 runs sampled)
inflate-imaya x 85.05 ops / sec ± 1.07% (71 runs sampled)
! inflate-pako x 97.58 ops / sec ± 0.69% (80 runs sampled)
inflate-pako-untyped x 18.06 ops / sec ± 0.65% (56 runs sampled)
inflate-zlib x 60.60 ops / sec ± 2.04% (67 runs sampled)


Please note that when layers are made to the system libraries, marshaling (forwarding objects to javascript and back) is not free. Therefore, on the “easy” inflate, a funny result is obtained when “javascript code is faster than the default one”. Of course it is not. In deflate tests, where the processor load is really high, the share of marshaling costs is small and the speed ratio looks plausible.

This is NOT asm.js. Normal javascript. Benchmarks, unfortunately, only under v8. But the speed ratio between other browsers can be viewed in the tracker of the well-known jszip library , the authors of which are now testing pako.

Source: https://habr.com/ru/post/216641/


All Articles