This repo contains benchmarks for two PHP routing libraries:
- Symfony Routing both compiled and dynamic mode
- FastRoute in group count mode and mark mode
Symfony Routing in dynamic mode sequentially matches each route pattern against a URI. In compiled mode it matches static routes via dictionary lookup and dynamic routes with one giant pre-compiled regex.
FastRoute in group count mode matches batches of 10 to 30 route patterns against a URI. In mark mode it basically works like Symfony's compiled mode.
composer run bench
This runs 10 iterations of the benchmarks after a warmup. The URLs are tested against around 300 routes which I exported from the open source application akaunting. I believe that the set of routes is representative for an medium sized application.
The following benchmarks are performed:
- URL that matches one of the first routes (with and without parameter)
- URL that matches a route in the middle (with and without parameter)
- URL that matches one of the last routes (with and without parameter)
- URL that does not match any route
The individual benchmarks can be run from the browser by serving public/index.php
.
cd public
php -S localhost:8000