Home

Awesome

PHP Router Benchmark

The intent here is to benchmark different PHP routing solutions. This is a micro-optimization, done purely out of dumb curiosity.

Installation

Clone the repo, run composer install, run php run-tests.php.

You can install the Pux extension to test that as well. If the extension is not installed, the tests will fallback to the pure PHP implementation of Pux.

To test the R3 library, you also need to install that extension. If the extension is not installed, the tests for R3 will be skipped.

Currently

The current test creates 1000 routes, each with a randomized prefix and postfix, with 9 parameters each.

It was run with the Pux and R3 extensions enabled.

An example route: /9b37eef21e/{arg1}/{arg2}/{arg3}/{arg4}/{arg5}/{arg6}/{arg7}/{arg8}/{arg9}/bda37e9f9b

Worst-case matching

This benchmark matches the last route and unknown route. It generates a randomly prefixed and suffixed route in an attempt to thwart any optimization. 1,000 routes each with 9 arguments.

This benchmark consists of 12 tests. Each test is executed 1,000 times, the results pruned, and then averaged. Values that fall outside of 3 standard deviations of the mean are discarded.

Test NameResultsTime+ IntervalChange
r3 - unknown route (1000 routes)9870.0000111161+0.0000000000baseline
r3 - last route (1000 routes)9940.0000135476+0.000002431622% slower
FastRoute - unknown route (1000 routes)9820.0003966292+0.00038551323468% slower
FastRoute - last route (1000 routes)9990.0004029198+0.00039180373525% slower
Pux ext - unknown route (1000 routes)9840.0008801297+0.00086901367818% slower
Symfony2 Dumped - unknown route (1000 routes)9810.0009883075+0.00097719148791% slower
Pux ext - last route (1000 routes)9990.0009942575+0.00098314148844% slower
Symfony2 Dumped - last route (1000 routes)9780.0010521817+0.00104106569365% slower
Symfony2 - unknown route (1000 routes)9890.0061380323+0.006126916355118% slower
Symfony2 - last route (1000 routes)9990.0061715401+0.006160424055419% slower
Aura v2 - last route (1000 routes)9820.1814854888+0.18147437271632542% slower
Aura v2 - unknown route (1000 routes)9770.1871979547+0.18718683861683932% slower

First route matching

This benchmark tests how quickly each router can match the first route. 1,000 routes each with 9 arguments.

This benchmark consists of 6 tests. Each test is executed 1,000 times, the results pruned, and then averaged. Values that fall outside of 3 standard deviations of the mean are discarded.

Test NameResultsTime+ IntervalChange
php-r3 - first route9890.0000097053+0.0000000000baseline
Pux ext - first route9850.0000209825+0.0000112773116% slower
FastRoute - first route9990.0000382496+0.0000285443294% slower
Symfony2 Dumped - first route9910.0000611150+0.0000514098530% slower
Symfony2 - first route9780.0002531449+0.00024343972508% slower
Aura v2 - first route9850.0003834265+0.00037372123851% slower