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 14 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)9970.0000078341+0.0000000000baseline
r3 - last route (1000 routes)9950.0000105369+0.000002702935% slower
Router - unknown route (1000 routes)9920.0000188012+0.0000109671140% slower
Router - last route (1000 routes)9920.0000199661+0.0000121321155% slower
FastRoute - unknown route (1000 routes)9890.0003324273+0.00032459334143% slower
FastRoute - last route (1000 routes)9980.0003505095+0.00034267544374% slower
Symfony2 Dumped - unknown route (1000 routes)9980.0008737620+0.000865928011053% slower
Pux ext - unknown route (1000 routes)9980.0009388064+0.000930972311884% slower
Pux ext - last route (1000 routes)9980.0010594999+0.001051665813424% slower
Symfony2 Dumped - last route (1000 routes)9980.0011358077+0.001127973614398% slower
Symfony2 - last route (1000 routes)9950.0048178922+0.004810058161399% slower
Symfony2 - unknown route (1000 routes)9940.0050545266+0.005046692664420% slower
Aura v2 - last route (1000 routes)9860.1500148822+0.15000704811914802% slower
Aura v2 - unknown route (1000 routes)9960.1623154067+0.16230757262071815% 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 8 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 route9970.0000078204+0.0000000000baseline
Pux ext - first route9990.0000160752+0.0000082548106% slower
Router - unkown route9940.0000186509+0.0000108304138% slower
Router - first route9920.0000213913+0.0000135709174% slower
FastRoute - first route9880.0000356728+0.0000278523356% slower
Symfony2 Dumped - first route9910.0000493382+0.0000415178531% slower
Symfony2 - first route9990.0001964001+0.00018857972411% slower
Aura v2 - first route9980.0003710765+0.00036325614645% slower