Benchmark
How pdf-raster compares with pdfjs-dist, how output size differs by format, and how to run the benchmark yourself.
The repository includes a benchmark that renders the same PDFs with
pdf-raster and with pdfjs-dist on two Node.js canvas backends,
@napi-rs/canvas and node-canvas.
- pdf-raster10.1 ms
- pdfjs-dist + @napi-rs/canvas17.6× slower176.9 ms
- pdfjs-dist + node-canvas25.5× slower256.9 ms
- pdf-raster17.1 ms
- pdfjs-dist + @napi-rs/canvas12.7× slower218.3 ms
- pdfjs-dist + node-canvas17.5× slower299.1 ms
Milliseconds per page at 300 DPI to PNG, one conversion at a time, on an Apple M4 with 24 GB, macOS 27, Bun 1.4.2. Shorter is faster. Both charts share one scale.
One machine, two PDFs
All numbers on this page come from an Apple M4 (4 performance and 6 efficiency cores, 24 GB) on macOS 27, running the benchmark under Bun 1.4.2. Your hardware and your PDFs will give different numbers. Run the benchmark to measure them.
Run it
bun run benchmarkFlags:
--libs <list>picks which libraries to run, frompdf-raster,pdfjs-napiandpdfjs-node-canvas. All three run by default.--output <format>sets the format,png,jpegorwebp.--concurrency <n>startsnconvert()calls at once and reports pages per second. It applies to pdf-raster only. The pdf.js backends always run one conversion at a time.--dpi <n>and--pages <list>set the resolution and the zero-based pages to render.--runs <n>and--warmups <n>set how many measured and warmup runs to do.--jsonprints a JSON report instead of tables.
Pass PDF paths as arguments to benchmark your own files. The command runs
inside benchmark/, so use absolute paths:
bun run benchmark -- /path/to/report.pdf --libs pdf-raster --output jpeg --concurrency 4node-canvas needs system libraries
node-canvas builds against Cairo and other system libraries. Install its
prerequisites first, or skip it with --libs pdf-raster,pdfjs-napi.
Fixtures and settings
The default fixtures are generated, letter-size PDFs written to
benchmark/.fixtures/, which git ignores:
text-20.pdfhas 20 pages of text.mixed-10.pdfhas 10 pages that alternate between text and a 1200 × 900 image.
bun run --cwd benchmark fixtures regenerates them. Each library renders at
300 DPI to PNG, with one warmup run followed by the measured runs.
Results
Output of bun run benchmark -- --runs 5 --warmups 1:
File: text-20.pdf (benchmark/.fixtures/text-20.pdf)
Settings: dpi=300, output=png, pages=all, warmups=1, runs=5, libs=pdf-raster,pdfjs-napi,pdfjs-node-canvas, concurrency=1
Input size: 112 KB
Library Pages Avg total P50 total Avg/page Pages/s Avg bytes
---------------------------- ----- ---------- ---------- --------- ------- ---------
pdf-raster 20 201.52 ms 200.93 ms 10.08 ms 99.3 58.9 MB
pdfjs-dist + @napi-rs/canvas 20 3538.56 ms 3534.54 ms 176.93 ms n/a 23.4 MB
pdfjs-dist + node-canvas 20 5137.57 ms 5136.13 ms 256.88 ms n/a 30.1 MB
Relative speed (pdf-raster vs pdfjs-dist + @napi-rs/canvas): total 17.56x
Relative speed (pdf-raster vs pdfjs-dist + node-canvas): total 25.49x
File: mixed-10.pdf (benchmark/.fixtures/mixed-10.pdf)
Settings: dpi=300, output=png, pages=all, warmups=1, runs=5, libs=pdf-raster,pdfjs-napi,pdfjs-node-canvas, concurrency=1
Input size: 2.9 MB
Library Pages Avg total P50 total Avg/page Pages/s Avg bytes
---------------------------- ----- ---------- ---------- --------- ------- ---------
pdf-raster 10 171.33 ms 170.26 ms 17.13 ms 58.4 52.9 MB
pdfjs-dist + @napi-rs/canvas 10 2182.96 ms 2184.32 ms 218.30 ms n/a 19.4 MB
pdfjs-dist + node-canvas 10 2990.47 ms 2990.91 ms 299.05 ms n/a 21.9 MB
Relative speed (pdf-raster vs pdfjs-dist + @napi-rs/canvas): total 12.74x
Relative speed (pdf-raster vs pdfjs-dist + node-canvas): total 17.45xA relative speed of 17.56x means the other library took 17.56 times as long
as pdf-raster for the whole run.
If a library fails on a PDF, the benchmark prints a skipped: line with the
error and continues with the others.
Output size
Avg bytes is the total output of one run. pdf-raster compresses PNGs with a
fast setting, so its PNG files are about 2.5 times larger than the ones
pdfjs-dist writes. For the 20 pages of text-20.pdf, that is 58.9 MB against
23.4 MB.
Average size per page from pdf-raster at 300 DPI:
| Format | text-20 | mixed-10 |
|---|---|---|
| PNG | 3016 KB | 5414 KB |
| WebP (lossless) | 965 KB | 2345 KB |
| JPEG (quality 75) | 1228 KB | 1124 KB |
WebP gives the smallest lossless output. On text pages it also beats JPEG. On pages with photos, JPEG is the smallest.
Throughput and concurrency
Pages per second from pdf-raster at 300 DPI, with 1 and 4 convert() calls
running at once:
| Format | Calls | text-20 | mixed-10 |
|---|---|---|---|
| PNG | 1 | 97.4 | 58.4 |
| PNG | 4 | 105.8 | 66.2 |
| JPEG | 1 | 59.7 | 47.7 |
| JPEG | 4 | 67.4 | 56.3 |
| WebP | 1 | 96.1 | 57.8 |
| WebP | 4 | 102.3 | 65.0 |
Extra calls add 6 to 18 percent, because PDFium renders one page at a time across the whole process. They help most with JPEG, where encoding takes a larger share of each page. PNG and WebP encode at almost the same speed.
Compared with 0.1.0
The published pdf-raster@0.1.0 on the same machine, text-20.pdf, one call
at a time, timed with the same settings (one warmup, five runs):
| Format | 0.1.0, pages/s | 0.2.0, pages/s | Change |
|---|---|---|---|
| PNG | 28.3 | 97.4 | 3.4× |
| JPEG | 14.1 | 59.7 | 4.2× |
| WebP | 36.8 | 96.1 | 2.6× |
JPEG moved to a faster encoder, and pages now encode in parallel outside the PDFium lock. Concurrency and memory explains the model.
What the numbers do and do not show
The benchmark measures end-to-end convert() time on two synthetic PDFs. Use
it to compare libraries on your hardware and to catch regressions between
versions. It does not predict the speed of every PDF. Pages with complex
vector art, many fonts or large images render slower.