A comprehensive benchmark suite comparing the performance of popular PHP template engines: Smarty4, Twig, Fenom, and Native PHP.
This project benchmarks four PHP template solutions across three test scenarios:
- Echo test - Substituting 10,000 variables
- Foreach test - Looping through 1000 items
- Inheritance test - Deep template inheritance (100 levels)
| Engine | Version | Description |
|---|---|---|
| Smarty4 | 4.5.6 | PHP Template Engine (LGPL-3.0) |
| Twig | 3.14+ | The flexible, fast, and secure template language |
| Fenom | 3.1.0 | Excellent template engine for PHP (BSD-3) |
| Native PHP | - | Plain PHP with extract() and output buffering |
- PHP >= 7.4 (tested up to PHP 8.4)
- Composer
composer installphp bin/fenom-benchmark.php--stress N- Run each template N times for stress testing--auto_reload- Enable auto-reload mode (recompile on change)--cleanup- Clean up compiled templates after benchmark
php bin/fenom-benchmark.php --stress 10 --cleanup./vendor/bin/phpunitOr with coverage:
./vendor/bin/phpunit --coverage-html coverage- Platform: macOS (Darwin)
- PHP Version: 8.4
- Date: April 2026
| Engine | !compiled !loaded | compiled !loaded | compiled loaded |
|---|---|---|---|
| native | 0.0002 sec | 0.0002 sec | 0.0002 sec |
| fenom | 0.0210 sec | 0.0036 sec | 0.0002 sec |
| smarty4 | 0.0654 sec | 0.0048 sec | 0.0003 sec |
| twig | 0.0736 sec | 0.0056 sec | 0.0005 sec |
Memory usage:
- native: 2.2 MiB
- fenom: 8.2-9.2 MiB
- smarty4: 10.0-19.1 MiB
- twig: 9.3-32.6 MiB
| Engine | !compiled !loaded | compiled !loaded | compiled loaded |
|---|---|---|---|
| native | 0.0002 sec | 0.0002 sec | 0.0002 sec |
| fenom | 0.0019 sec | 0.0004 sec | 0.0003 sec |
| smarty4 | 0.0038 sec | 0.0006 sec | 0.0003 sec |
| twig | 0.0057 sec | 0.0015 sec | 0.0012 sec |
Memory usage:
- native: 2.0 MiB
- fenom: 2.2-2.9 MiB
- smarty4: 2.5-4.2 MiB
- twig: 2.9-4.1 MiB
| Engine | !compiled !loaded | compiled !loaded | compiled loaded |
|---|---|---|---|
| native | N/A | N/A | N/A |
| fenom | 0.0062 sec | 0.0001 sec | 0.0000 sec |
| smarty4 | 0.0382 sec | 0.0043 sec | 0.0035 sec |
| twig | 0.0365 sec | 0.0051 sec | 0.0002 sec |
Memory usage:
- fenom: 2.2-3.7 MiB
- smarty4: 6.6-8.6 MiB
- twig: 6.8-9.1 MiB
Note: Native PHP does not support template inheritance natively.
| Rank | Engine | First Run | Cached (loaded) | Memory |
|---|---|---|---|---|
| 1 | Native PHP | 0.0002s | 0.0002s | ~2 MiB |
| 2 | Fenom | 0.0210s | 0.0002s | ~8 MiB |
| 3 | Smarty4 | 0.0654s | 0.0003s | ~10 MiB |
| 4 | Twig | 0.0736s | 0.0005s | ~10-32 MiB |
- Native PHP is fastest - but lacks features like template inheritance, caching, and security escaping
- Fenom is fastest among full-featured engines - excellent for high-traffic sites
- Smarty4 and Twig are comparable - Smarty4 has better first-run performance, Twig has better cached performance for inheritance
- All engines show significant caching benefits - first-run is 100-300x slower than cached
benchmark/
├── bin/
│ ├── fenom-benchmark.php # Main benchmark runner
│ └── engine.php # Engine launcher
├── compile/ # Compiled templates cache
├── src/
│ └── Benchmark.php # Benchmark class
├── templates/
│ ├── echo/ # Echo variable test
│ ├── foreach/ # Foreach loop test
│ └── inheritance/ # Template inheritance test
├── tests/
│ └── BenchmarkTest.php # PHPUnit tests
├── composer.json
├── phpunit.xml
├── README.md
└── README_ru.md
BSD-3-Clause
- Ivan Shalganov
- Dmitry Patsura
- Maxim Kostjukevich