PHPackages                             fenom/benchmark - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. fenom/benchmark

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

fenom/benchmark
===============

Benchmark of templates

22Go Template

Since May 22Pushed 2w ago5 watchersCompare

[ Source](https://github.com/fenom-template/benchmark)[ Packagist](https://packagist.org/packages/fenom/benchmark)[ RSS](/packages/fenom-benchmark/feed)WikiDiscussions master Synced yesterday

READMEChangelogDependenciesVersions (1)Used By (0)

PHP Template Engine Benchmark
=============================

[](#php-template-engine-benchmark)

A comprehensive benchmark suite comparing the performance of popular PHP template engines: **Smarty4**, **Twig**, **Fenom**, and **Native PHP**.

Overview
--------

[](#overview)

This project benchmarks four PHP template solutions across three test scenarios:

1. **Echo test** - Substituting 10,000 variables
2. **Foreach test** - Looping through 1000 items
3. **Inheritance test** - Deep template inheritance (100 levels)

Engines Tested
--------------

[](#engines-tested)

EngineVersionDescription**Smarty4**4.5.6PHP Template Engine (LGPL-3.0)**Twig**3.14+The flexible, fast, and secure template language**Fenom**3.1.0Excellent template engine for PHP (BSD-3)**Native PHP**-Plain PHP with extract() and output bufferingRequirements
------------

[](#requirements)

- PHP &gt;= 7.4 (tested up to PHP 8.4)
- Composer

Installation
------------

[](#installation)

```
composer install
```

Running Benchmarks
------------------

[](#running-benchmarks)

```
php bin/fenom-benchmark.php
```

### Options

[](#options)

- `--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

### Example

[](#example)

```
php bin/fenom-benchmark.php --stress 10 --cleanup
```

Running Tests
-------------

[](#running-tests)

```
./vendor/bin/phpunit
```

Or with coverage:

```
./vendor/bin/phpunit --coverage-html coverage
```

Benchmark Results
-----------------

[](#benchmark-results)

### Test Environment

[](#test-environment)

- **Platform**: macOS (Darwin)
- **PHP Version**: 8.4
- **Date**: April 2026

---

### Test 1: Echo Variable Substitution (10,000 variables)

[](#test-1-echo-variable-substitution-10000-variables)

Engine!compiled !loadedcompiled !loadedcompiled loaded**native**0.0002 sec0.0002 sec0.0002 sec**fenom**0.0210 sec0.0036 sec0.0002 sec**smarty4**0.0654 sec0.0048 sec0.0003 sec**twig**0.0736 sec0.0056 sec0.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

---

### Test 2: Foreach Loop (1000 items, 10 fields each)

[](#test-2-foreach-loop-1000-items-10-fields-each)

Engine!compiled !loadedcompiled !loadedcompiled loaded**native**0.0002 sec0.0002 sec0.0002 sec**fenom**0.0019 sec0.0004 sec0.0003 sec**smarty4**0.0038 sec0.0006 sec0.0003 sec**twig**0.0057 sec0.0015 sec0.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

---

### Test 3: Deep Template Inheritance (100 levels)

[](#test-3-deep-template-inheritance-100-levels)

Engine!compiled !loadedcompiled !loadedcompiled loaded**native**N/AN/AN/A**fenom**0.0062 sec0.0001 sec0.0000 sec**smarty4**0.0382 sec0.0043 sec0.0035 sec**twig**0.0365 sec0.0051 sec0.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.*

---

Summary
-------

[](#summary)

RankEngineFirst RunCached (loaded)Memory1**Native PHP**0.0002s0.0002s~2 MiB2**Fenom**0.0210s0.0002s~8 MiB3**Smarty4**0.0654s0.0003s~10 MiB4**Twig**0.0736s0.0005s~10-32 MiB### Key Findings

[](#key-findings)

1. **Native PHP is fastest** - but lacks features like template inheritance, caching, and security escaping
2. **Fenom is fastest among full-featured engines** - excellent for high-traffic sites
3. **Smarty4 and Twig are comparable** - Smarty4 has better first-run performance, Twig has better cached performance for inheritance
4. **All engines show significant caching benefits** - first-run is 100-300x slower than cached

Project Structure
-----------------

[](#project-structure)

```
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

```

License
-------

[](#license)

BSD-3-Clause

Authors
-------

[](#authors)

- Ivan Shalganov
- Dmitry Patsura
- Maxim Kostjukevich

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance63

Regular maintenance activity

Popularity5

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 61.5% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/135c5c250b5bf3601bec3f76db32610c07970441b96a557d0a7a767187912511?d=identicon)[bzick](/maintainers/bzick)

---

Top Contributors

[![ovr](https://avatars.githubusercontent.com/u/572096?v=4)](https://github.com/ovr "ovr (8 commits)")[![maxisoft-git](https://avatars.githubusercontent.com/u/2070199?v=4)](https://github.com/maxisoft-git "maxisoft-git (3 commits)")[![bzick](https://avatars.githubusercontent.com/u/345384?v=4)](https://github.com/bzick "bzick (2 commits)")

### Embed Badge

![Health badge](/badges/fenom-benchmark/health.svg)

```
[![Health](https://phpackages.com/badges/fenom-benchmark/health.svg)](https://phpackages.com/packages/fenom-benchmark)
```

###  Alternatives

[bensampo/laravel-embed

Painless responsive embeds for videos, slideshows and more.

142146.8k](/packages/bensampo-laravel-embed)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
