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
| Parameter | Value |
|---|---|
| CPU | Intel Core i9-13900K (x86-64) |
| RAM | 64 GB DDR5 (Docker limited to 16 GB) |
| Docker | 4 CPUs, 16 GB RAM, Ubuntu bookworm |
| PHP | 8.5.3 (CLI, OPcache enabled, JIT enabled) |
| TCPDF-Next | 1.6.0 |
| TCPDF | 6.10.1 |
| DomPDF | v3.1.4 |
| mPDF | v8.2.7 |
| Warmup | 3 iterations (discarded) |
| Measured | 20 iterations (median reported) |
| Measurement | hrtime(true) nanosecond-precision wall clock |
Interactive Comparison
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.
| Library | Time (ms) | Peak Memory (MB) | File Size (KB) |
|---|---|---|---|
| TCPDF-Next | 0.8 | 4 | 3.0 |
| TCPDF | 2.4 (2.9x slower) | 12 (3.0x) | 7.1 (2.4x) |
| DomPDF | 4.1 (5.1x slower) | 12 (3.0x) | 1.7 (0.6x) |
| mPDF | 7.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.
| Library | Time (ms) | Peak Memory (MB) | File Size (KB) |
|---|---|---|---|
| TCPDF | 1.2 | 16 | 9.2 |
| TCPDF-Next | 1.6 | 16 | 51.4 |
| DomPDF | 19.0 (11.6x slower than Next) | 16 | 4.0 |
| mPDF | 21.4 (13.1x slower than Next) | 18 | 30.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.
| Library | Time (ms) | Peak Memory (MB) | File Size (KB) |
|---|---|---|---|
| TCPDF-Next | 29.8 | 18 | 95.3 |
| TCPDF | 99.6 (3.3x slower) | 18 | 100.8 |
| mPDF | 1,064.5 (35.7x slower) | 82 (4.6x) | 181.1 |
| DomPDF | 2,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.
| Library | Time (ms) | Peak Memory (MB) | File Size (KB) |
|---|---|---|---|
| TCPDF-Next | 0.9 | 74 | 6.3 |
| TCPDF | 8.2 (9.0x slower) | 74 | 12.6 |
| DomPDF | 17.6 (19.2x slower) | 74 | 5.3 |
| mPDF | 34.0 (37.1x slower) | 72 | 46.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
| Mode | TCPDF-Next | TCPDF | DomPDF | mPDF |
|---|---|---|---|---|
| Single Thread | 2,632.7 | 1,183.9 | 264.6 | 131.3 |
| 4 Workers | 9,742.9 | 4,371.9 | 963.9 | 479.4 |
Documents per Minute
| Mode | TCPDF-Next | TCPDF | DomPDF | mPDF |
|---|---|---|---|---|
| Single Thread | 157,964 | 71,036 | 15,878 | 7,876 |
| 4 Workers | 584,574 | 262,316 | 57,836 | 28,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 Level | Additional 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.
| Feature | Additional 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:
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.
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.
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.
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.
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.
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 withmicrotime()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:
cd benchmark
docker compose up --buildResults are printed to stdout at the end of the run. The Docker setup ensures an identical environment regardless of host OS.
Further Reading
- Migration from TCPDF — Step-by-step migration guide
- Performance Tuning — Streaming mode, memory optimization, and caching strategies