Simple Text Rendering Benchmark

The Python PDF generation library ReportLab contains a demo/benchmarking application that takes the Project Gutenberg text of Homer’s Odyssey (contains about 12.000 lines and about 700.000 characters) and creates a PDF version from it. This benchmark is derived from that demo.

No advanced text features are used or needed by this benchmark, only the raw text output performance is tested.

Benchmark Setup

The text of the Odyssey is written onto A4 pages with a margin of 72 points, showing each line of the source text using the most basic text drawing methods available, without line wrapping or text measuring.

To see how the amount of text influences the performance, the benchmark is done by concatenating the text multiple times (1x, 5x and 10x by default). Additionally, all multiplication factors are combined once with the standard PDF Type1 font Times-Roman and once with a TrueType font (DejaVu Sans by default).

Each benchmark script (except the jPDFWriter and pdfkit ones) can be invoked standalone in the following way: script-executable TXT_FILE OUTPUT_FILE [TTF_FILE].

The list of the benchmarked libraries:

HexaPDF

Homepage: http://hexapdf.gettalong.org
Language: Ruby
Version: Latest version

Prawn

Homepage: https://prawnpdf.org
Language: Ruby
Version: 2.5.0

ReportLab

Homepage: https://www.reportlab.com/opensource/
Language: Python
Version: 4.2.2 + accel extension

ReportLab has a module that implements some features in C to speed up the execution. This module is used in the benchmark.

fpdf2

Homepage: https://pyfpdf.github.io/fpdf2/
Language: Python
Version: 2.7.9

jPDFWriter

Homepage: https://www.qoppa.com/pdfwriter/
Language: Java
Version: v2016R1

Qoppa Software provides the free jPDFWriter library which is needed for benchmarking this library. The Java source code file for the benchmark needs to be compiled and the jPDFWriter-JAR put onto the CLASSPATH environment variable.

Note that TrueType fonts don’t seem to be supported.

TCPDF

Homepage: https://tcpdf.org/
Language: PHP
Version: 6.7.5

PDF::API2

Homepage: http://search.cpan.org/perldoc/PDF::API2
Language: Perl
Version: 2.047

PDFKit

Homepage: https://pdfkit.org/
Language: Javascript
Version: 1.0.0

Results

These benchmark results are from 2025-01-04.

benchmark graphic

    Time Memory File size
hexapdf 1x 377ms 29.748KiB 446.555
prawn 1x 308ms 27.356KiB 616.765
reportlab/C 1x 256ms 49.388KiB 474.492
fpdf2 1x 347ms 73.116KiB 485.475
jPDFWriter 1x 391ms 109.404KiB 569.421
tcpdf 1x 410ms 35.696KiB 627.074
PDF::API2 1x 460ms 30.480KiB 455.322
pdfkit 1x 840ms 94.528KiB 637.581
hexapdf 5x 839ms 37.752KiB 2.227.477
prawn 5x 778ms 47.200KiB 3.084.301
reportlab/C 5x 520ms 66.100KiB 2.372.212
fpdf2 5x 577ms 85.224KiB 2.429.354
jPDFWriter 5x 553ms 235.888KiB 2.849.342
tcpdf 5x 1.842ms 48.964KiB 3.112.669
PDF::API2 5x 1.977ms 45.200KiB 2.276.997
pdfkit 5x 2.026ms 139.876KiB 3.189.607
hexapdf 10x 1.452ms 49.804KiB 4.454.997
prawn 10x 1.403ms 72.864KiB 6.170.089
reportlab/C 10x 885ms 86.568KiB 4.745.535
fpdf2 10x 904ms 100.628KiB 4.860.132
jPDFWriter 10x 828ms 358.412KiB 5.700.015
tcpdf 10x 3.723ms 65.260KiB 6.221.294
PDF::API2 10x 3.865ms 63.384KiB 4.555.402
pdfkit 10x 3.658ms 169.192KiB 6.380.272
hexapdf 1x ttf 447ms 31.164KiB 540.709
prawn 1x ttf 436ms 31.788KiB 634.595
reportlab/C 1x ttf 373ms 54.340KiB 624.176
fpdf2 1x ttf 830ms 79.360KiB 584.731
ERR jPDFWriter 1x ttf 0ms 0KiB 0
tcpdf 1x ttf 536ms 39.708KiB 758.150
PDF::API2 1x ttf 4.248ms 51.672KiB 668.754
pdfkit 1x ttf 1.219ms 146.548KiB 726.257
hexapdf 5x ttf 1.159ms 43.896KiB 2.640.625
prawn 5x ttf 1.240ms 50.932KiB 3.096.621
reportlab/C 5x ttf 1.100ms 78.220KiB 3.039.368
fpdf2 5x ttf 2.831ms 90.636KiB 2.857.521
ERR jPDFWriter 5x ttf 0ms 0KiB 0
tcpdf 5x ttf 2.441ms 56.568KiB 3.573.802
PDF::API2 5x ttf 20.482ms 75.892KiB 3.083.924
pdfkit 5x ttf 2.504ms 183.548KiB 3.568.200
hexapdf 10x ttf 2.075ms 58.776KiB 5.267.138
prawn 10x ttf 2.284ms 76.976KiB 6.175.486
reportlab/C 10x ttf 2.024ms 108.020KiB 6.059.897
fpdf2 10x ttf 5.431ms 113.020KiB 5.699.775
ERR jPDFWriter 10x ttf 0ms 0KiB 0
tcpdf 10x ttf 4.872ms 81.808KiB 7.095.070
PDF::API2 10x ttf 40.940ms 106.572KiB 6.104.416
pdfkit 10x ttf 4.143ms 210.004KiB 7.120.880