A comparison between sharp vs resvg-js performance to bulk convert SVGs to PNGs.
Sharp configuration: scripts/benchmark/sharp.js
rsvg-js configuration: scripts/benchmark/resvg.js
-
Install dependencies:
pnnpm i
-
Benchmark:
pnpm benchmark
When converting 400 SVG icons from simple-icons to 2500 DPI 800px width PNGs, sharp is 3x faster than resvg-js.
resvg: { duration: '5472ms', icons: 400 }
sharp: { duration: '1569ms', icons: 400 }
sharp is faster by 3.49x
The number of icons is limited to 400 because when processing too many icons at once, resvg-js crashes the whole Node.js process:
$ pnpm benchmark
> node scripts/benchmark
thread '<unnamed>' panicked at 'the previous segment must be M/L/C', /Users/runner/.cargo/git/checkouts/resvg-4b7e4ee32ad6d954/cab0b15/usvg/src/pathdata.rs:160:17
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
fatal runtime error: failed to initiate panic, error 5
After benchmarking, the resulting PNGs are saved to pngs/
. When comparing icons between sharp and rsvg, the DPI on sharp is 2400 (as expected), but the DPI on resvg-js is 72.
Zoom in to compare difference
resvg-js - 11.1 KB - 72 DPI | sharp - 16.6 KB - 2400 DPI |
---|---|