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 2018-12-31.
|hexapdf L||400 ttf||1.205ms||78.780KiB||445.397|
|hexapdf C||400 ttf||1.299ms||94.004KiB||445.419|
|hexapdf L||200 ttf||1.336ms||82.448KiB||508.010|
|hexapdf C||200 ttf||1.503ms||90.968KiB||508.035|
|hexapdf L||100 ttf||1.639ms||82.216KiB||611.454|
|hexapdf C||100 ttf||1.929ms||90.508KiB||611.473|
|hexapdf L||50 ttf||4.250ms||277.196KiB||772.064|
|hexapdf C||50 ttf||5.117ms||271.416KiB||772.079|