New benchmark: Mezon Router is up to 567 times faster than Zaphpa Router

Hi all! Today we have one more benchmark.

As usual we have two cases:

  1. http server accepts request, launches php script, which handles this request, and then all script data is removed from memory. All following requests are processed in the same way. In this case very critical to launch script as soon as possible and we do not have time for long pre-compilations and preparations. Because all of it will be lost after the script will finish working;
  2. php script is launching, initiating all internal components (and router is one of them) and then starting processing requests. This case can be organized via for example react-php. It differs from the previous case because we can spend reasonable time to pre-compile routes for faster processing.

The first case

// static routes
$_SERVER['REQUEST_METHOD'] = 'GET';
$_SERVER['REQUEST_URI'] = '/static/0';
$router = RouteGenerator::generateZaphpaStaticRoutes(1000);
$router->route();
$_SERVER['REQUEST_METHOD'] = 'GET';
$_SERVER['REQUEST_URI'] = '/static/99';
$router = RouteGenerator::generateZaphpaStaticRoutes(1000);
$router->route();
$_SERVER['REQUEST_METHOD'] = 'GET';
$_SERVER['REQUEST_URI'] = '/static/199';
$router = RouteGenerator::generateZaphpaStaticRoutes(1000);
$router->route();
// and so on up to /static/999 route
// non static routes
$_SERVER['REQUEST_METHOD'] = 'GET';
$_SERVER['REQUEST_URI'] = '/param/0/1/';
$router = RouteGenerator::generateZaphpaNonStaticRoutes(1000);
$router->route();
$_SERVER['REQUEST_METHOD'] = 'GET';
$_SERVER['REQUEST_URI'] = '/param/99/1/';
$router = RouteGenerator::generateZaphpaNonStaticRoutes(1000);
$router->route();
$_SERVER['REQUEST_METHOD'] = 'GET';
$_SERVER['REQUEST_URI'] = '/param/199/1/';
$router = RouteGenerator::generateZaphpaNonStaticRoutes(1000);
$router->route();
// and so on up to /param/999/1 route

The second case

// static routes
$router = RouteGenerator::generateZaphpaStaticRoutes(1000);
$_SERVER['REQUEST_METHOD'] = 'GET';
$_SERVER['REQUEST_URI'] = '/static/0';
$router->route();
$_SERVER['REQUEST_METHOD'] = 'GET';
$_SERVER['REQUEST_URI'] = '/static/99';
$router->route();
$_SERVER['REQUEST_METHOD'] = 'GET';
$_SERVER['REQUEST_URI'] = '/static/199';
$router->route();
// and so on up to /static/999 route
// non static routes
$router = RouteGenerator::generateZaphpaNonStaticRoutes(1000);
$_SERVER['REQUEST_METHOD'] = 'GET';
$_SERVER['REQUEST_URI'] = '/param/0/1/';
$router->route();
$_SERVER['REQUEST_METHOD'] = 'GET';
$_SERVER['REQUEST_URI'] = '/param/99/1/';
$router->route();
$_SERVER['REQUEST_METHOD'] = 'GET';
$_SERVER['REQUEST_URI'] = '/param/199/1/';
$router->route();
// and so on up to /param/999/1 route

OK What do we have?

The first case + static routes

+------------------------------------+--------+
| benchmark | diff |
+------------------------------------+--------+
| CoffeeSingleRequestStaticBench | 11.74x |
| DVKSingleRequestStaticBench | 7.05x |
| HoaSingleRequestStaticBench | 12.72x |
| IBSingleRequestStaticBench | 34.88x |
| MezonSingleRequestStaticBench | 2.56x |
| MiladSingleRequestStaticBench | 8.28x |
| PeceeSingleRequestStaticBench | 10.62x |
| PowerSingleRequestStaticBench | 5.80x |
| SteampixelSingleRequestStaticBench | 66.50x |
| ToroSingleRequestStaticBench | 1.00x |
| ZaphpaSingleRequestStaticBench | 17.06x |
+------------------------------------+--------+

The first case + non-static routes

+-----------------------------------+--------+
| benchmark | diff |
+-----------------------------------+--------+
| CoffeeSingleRequestParamBench | 3.72x |
| DVKSingleRequestParamBench | 1.99x |
| HoaSingleRequestParamBench | 2.78x |
| IBSingleRequestParamBench | 8.75x |
| MezonSingleRequestParamBench | 8.42x |
| MiladSingleRequestParamBench | 2.13x |
| PeceeSingleRequestParamBench | 4.55x |
| PowerSingleRequestParamBench | 1.36x |
| SteampixelSingleRequestParamBench | 19.92x |
| ToroSingleRequestParamBench | 1.00x |
| ZaphpaSingleRequestParamBench | 4.94x |
+-----------------------------------+--------+

The second case + static routes

+----------------------------+------------+
| benchmark | diff |
+----------------------------+------------+
| CoffeeReactStaticBench | 381.38x |
| DVKReactStaticBench | 492.29x |
| HoaReactStaticBench | 164.61x |
| IBReactStaticBench | 1,219.60x |
| MezonReactStaticBench | 1.00x |
| MiladReactStaticBench | 799.16x |
| PeceeReactStaticBench | 896.31x |
| PowerReactStaticBench | 791.97x |
| SteampixelReactStaticBench | 11,353.55x |
| ToroReactStaticBench | 17.73x |
| ZaphpaReactStaticBench | 566.75x |
+----------------------------+------------+

The second case + non-static routes

+---------------------------+---------+
| benchmark | diff |
+---------------------------+---------+
| CoffeeReactParamBench | 7.94x |
| DVKReactParamBench | 12.29x |
| HoaReactParamBench | 3.93x |
| IBReactParamBench | 33.08x |
| MezonReactParamBench | 1.00x |
| MiladReactParamBench | 20.17x |
| PeceeReactParamBench | 53.15x |
| PowerReactParamBench | 32.70x |
| SteampixelReactParamBench | 319.20x |
| ToroReactParamBench | 9.86x |
| ZaphpaReactParamBench | 23.99x |
+---------------------------+---------+

As you can see almost in all cases Mezon Router is faster that Zaphpa router.

What’s next?

More articles can be found in my Twitter

What is mezon/router?

mezon/router now is:

  • framework for routing with 100% code coverage
  • 10.0 points on scrutinizer-ci.com
  • router is a part of the Mezon Project

Repo on github.com: https://github.com/alexdodonov/mezon-router

It will be great if you will contribute something to this project. Documentation, sharing the project in your social media, bug fixing, refactoring, or even submitting issue with question or feature request. Thanks anyway )

php developer