Skip to content

Performance Benchmarks

This page presents real-world performance benchmarks comparing TCPDF-Next against three established PHP PDF libraries: TCPDF, DomPDF, and mPDF. All benchmarks were executed on identical hardware under controlled Docker conditions. We report medians, not averages, to eliminate outlier distortion. Where TCPDF-Next is not the fastest, we say so honestly.

Test Environment

ParameterValue
CPUIntel Core i9-13900K (x86-64)
RAM64 GB DDR5 (Docker limited to 16 GB)
Docker4 CPUs, 16 GB RAM, Ubuntu bookworm
PHP8.5.3 (CLI, OPcache enabled, JIT enabled)
TCPDF-Next1.6.0
TCPDF6.10.1
DomPDFv3.1.4
mPDFv8.2.7
Warmup3 iterations (discarded)
Measured20 iterations (median reported)
Measurementhrtime(true) nanosecond-precision wall clock

Interactive Comparison

▼ Lower is better
TCPDF-Next
0.8 ms
TCPDF
2.4 ms3.0x
DomPDF
4.1 ms5.1x
mPDF
7.2 ms9.0x

PHP 8.5.3 + JIT · Docker 4 CPUs / 16 GB · i9-13900K · Median of 20 runs

Generation Speed

Each scenario was run 20 times after warmup. The tables below show median generation time, peak memory, output file size, and relative speed compared to TCPDF-Next.

Simple Document (1 Page)

A single A4 page with a heading and basic formatted text. No images, no tables.

LibraryTime (ms)Peak Memory (MB)File Size (KB)
TCPDF-Next0.843.0
TCPDF2.4 (2.9x slower)12 (3.0x)7.1 (2.4x)
DomPDF4.1 (5.1x slower)12 (3.0x)1.7 (0.6x)
mPDF7.2 (8.9x slower)16 (4.0x)28.0 (9.3x)

TCPDF-Next completes the simplest scenario in under 1 ms — nearly 3x faster than TCPDF, 5x faster than DomPDF, and 9x faster than mPDF.

Invoice (2 Pages)

A two-page invoice with tabular line items, totals, headers, and footers.

LibraryTime (ms)Peak Memory (MB)File Size (KB)
TCPDF1.2169.2
TCPDF-Next1.61651.4
DomPDF19.0 (11.6x slower than Next)164.0
mPDF21.4 (13.1x slower than Next)1830.2

Honesty Note

In the Invoice scenario, TCPDF is 1.4x faster than TCPDF-Next (1.2 ms vs 1.6 ms). TCPDF also produces a smaller output file (9.2 KB vs 51.4 KB). This is likely due to TCPDF's highly optimized legacy table layout engine for simple tabular content. Both libraries still significantly outperform DomPDF and mPDF in this scenario.

100-Page Report

A 100-page document with dense mixed content: headings, paragraphs, and structured data across many pages.

LibraryTime (ms)Peak Memory (MB)File Size (KB)
TCPDF-Next29.81895.3
TCPDF99.6 (3.3x slower)18100.8
mPDF1,064.5 (35.7x slower)82 (4.6x)181.1
DomPDF2,715.6 (91.1x slower)70 (3.9x)128.7

The 100-page scenario is where TCPDF-Next truly separates itself. At 29.8 ms, it is 3.3x faster than TCPDF and a staggering 91x faster than DomPDF. Memory usage is identical to TCPDF and drastically lower than both DomPDF and mPDF.

HTML to PDF

Converting an HTML fragment to PDF using each library's built-in HTML parsing engine.

LibraryTime (ms)Peak Memory (MB)File Size (KB)
TCPDF-Next0.9746.3
TCPDF8.2 (9.0x slower)7412.6
DomPDF17.6 (19.2x slower)745.3
mPDF34.0 (37.1x slower)7246.0

TCPDF-Next's HTML parsing engine delivers sub-millisecond performance — 9x faster than TCPDF and 37x faster than mPDF. All four libraries consume roughly the same peak memory in this scenario, indicating the overhead is dominated by the HTML parsing infrastructure itself.

Throughput

Throughput measures how many simple documents (1-page) each library can generate per second and per minute under sustained load.

Documents per Second

ModeTCPDF-NextTCPDFDomPDFmPDF
Single Thread2,632.71,183.9264.6131.3
4 Workers9,742.94,371.9963.9479.4

Documents per Minute

ModeTCPDF-NextTCPDFDomPDFmPDF
Single Thread157,96471,03615,8787,876
4 Workers584,574262,31657,83628,762

With 4 workers, TCPDF-Next sustains nearly 10,000 documents per second — over 584,000 documents per minute. This is 2.2x the throughput of TCPDF, 10x DomPDF, and 20x mPDF. For high-volume batch processing (invoicing, reporting, statement generation), these throughput numbers translate directly into infrastructure cost savings.

Digital Signature Overhead (PAdES)

Time and size overhead for digitally signing a 10-page document at each PAdES conformance level. Only TCPDF-Next supports built-in PAdES digital signatures; other libraries are not included in this comparison.

Signature LevelAdditional Time (ms)Additional File Size (KB)
PAdES B-B+15+5-8
PAdES B-T+120*+8-12
PAdES B-LT+250*+15-50
PAdES B-LTA+350*+20-60

*Includes network round-trip to TSA/OCSP servers. Actual time depends on server latency and network conditions.

TIP

PAdES B-B (basic signature) adds only ~15 ms and 5-8 KB — negligible for most workflows. Higher levels (B-T, B-LT, B-LTA) introduce network-dependent latency from timestamp authority and OCSP responder calls.

PDF/A-4 Archival Overhead

Overhead of generating PDF/A-4 compliant output compared to standard PDF 2.0 output.

FeatureAdditional Size
sRGB ICC profile+3 KB
XMP metadata+2-5 KB
Output intent+1-3 KB
Full font embedding (if required)+50-500 KB per font
Typical total overhead+10-50 KB
Generation time overhead< 5%

TIP

Font subsetting is still used by default in PDF/A-4 mode. The overhead comes mainly from the ICC profile and expanded metadata. For most documents, the PDF/A-4 overhead is negligible.

Why TCPDF-Next Is Fast

TCPDF-Next's performance advantages stem from deliberate architectural decisions:

  1. Modern PDF 2.0 core — The rendering pipeline was built from scratch for PDF 2.0, eliminating legacy compatibility layers that slow down TCPDF. Cross-reference streams and object streams reduce both I/O and file size.

  2. JIT-friendly code paths — Hot loops and critical rendering methods are structured to benefit from PHP 8's JIT compiler. Tight, typed code with minimal branching allows the JIT to generate efficient machine code.

  3. Lazy resource loading — Fonts, images, and ICC profiles are loaded on first use, not at construction time. Documents that do not embed images pay zero image-processing overhead.

  4. Efficient memory layout — Page objects are compacted and reuse shared resources (fonts, color spaces) via reference counting. This keeps peak memory low even for long documents.

  5. Optimized HTML parser — Instead of regex-based HTML parsing (as used by legacy TCPDF), TCPDF-Next uses a streaming token-based parser that processes HTML in a single pass with minimal backtracking.

  6. Parallelizable design — The stateless page-rendering architecture allows workloads to scale linearly across multiple workers, as demonstrated by the near-4x throughput gain with 4 workers.

Methodology

  • Warmup: 3 iterations are executed and discarded before measurement begins, ensuring OPcache and JIT are fully warmed.
  • Iterations: 20 measured iterations per scenario. The median is reported to eliminate outlier noise.
  • Timing: hrtime(true) provides nanosecond-precision wall-clock measurement, avoiding issues with microtime() clock drift.
  • Memory: memory_get_peak_usage(true) reports real (RSS) peak memory allocated by the PHP runtime.
  • File size: Output is written to a temporary file and measured with filesize().
  • Isolation: Each benchmark runs in its own process to prevent cross-test memory contamination.
  • Environment: All libraries run inside the same Docker container with identical PHP configuration, CPU limits, and memory limits.

Reproducing the Benchmarks

The benchmark suite is included in the repository. To reproduce these results:

bash
cd benchmark
docker compose up --build

Results are printed to stdout at the end of the run. The Docker setup ensures an identical environment regardless of host OS.

Further Reading

Released under the LGPL-3.0-or-later License.