Line Wrapping Benchmark
This benchmark tests the performance of line wrapping and simple general layouting. The Project Gutenberg text of Homer’s Odyssey is used for this purposes.
The text of the Odyssey is arranged on pages of the dimension
WIDTH is set to
different values (400, 200, 100 and 50 by default). Additionally, all widths are combined once with
the standard PDF Type1 font Times-Roman and once with a TrueType font (DejaVu Sans by default).
In the case of pages with a width of 400 no line wrapping needs to be done because each line in the source text is shorter than 400 points. In the other cases lines need to be actually wrapped and the number of pages increases. With a width of 50 even words need sometimes to be broken.
Each benchmark script can be invoked standalone in the following way:
WIDTH OUTPUT_FILE [TTF_FILE].
The performance of the libraries hugely depends on how the input text is provided: Some are very fast when processing the whole input file at once, others only when processing the input line by line. The fastest method was always chosen.
The list of the benchmarked libraries:
Version: Latest version
HexaPDF works faster if the whole input is given at once but still has acceptable runtimes for line by line input.
Two different ways of general layouting are benchmarked:
Prawn is much faster and uses much less memory if the input is provided line by line. However, it still works if the whole input is provided at once.
ReportLab also needs its input line by line. Otherwise it is much, much slower (at least 60x, then the test run was aborted).
As with Prawn and ReportLab, TCPDF needs its input line by line. Otherwise it is much, much slower when line wrapping needs to be done (the test run was aborted because it took too long).
These benchmark results are from 2020-12-27.
|hexapdf L||400 ttf||1.361ms||91.588KiB||445.397|
|hexapdf C||400 ttf||1.531ms||108.304KiB||445.421|
|hexapdf L||200 ttf||1.544ms||85.652KiB||508.009|
|hexapdf C||200 ttf||1.777ms||98.704KiB||508.036|
|hexapdf L||100 ttf||1.861ms||86.696KiB||611.454|
|hexapdf C||100 ttf||2.490ms||96.508KiB||611.477|
|hexapdf L||50 ttf||4.675ms||254.304KiB||772.063|
|hexapdf C||50 ttf||5.727ms||290.032KiB||772.076|