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
$router = RouteGenerator::generateJoomlaStaticRoutes(1000);
$controller = $router->getController('/static/0');
$controller->execute();
$router = RouteGenerator::generateJoomlaStaticRoutes(1000);
$controller = $router->getController('/static/99');
$controller->execute();
$router = RouteGenerator::generateJoomlaStaticRoutes(1000);
$controller = $router->getController('/static/199');
$controller->execute();
// and so on up to /static/999 route
// non static routes
$router = RouteGenerator::generateJoomlaNonStaticRoutes(1000);
$controller = $router->getController('/param/1/0');
$controller->execute();
$router = RouteGenerator::generateJoomlaNonStaticRoutes(1000);
$controller = $router->getController('/param/1/99');
$controller->execute();
$router = RouteGenerator::generateJoomlaNonStaticRoutes(1000);
$controller = $router->getController('/param/1/199');
$controller->execute();
// and so on up to /param/999/1 route

The second case

// static routes
$router = RouteGenerator::generateJoomlaStaticRoutes(1000);
$controller = $router->getController('/static/0');
$controller->execute();
$controller = $router->getController('/static/99');
$controller->execute();
$controller = $router->getController('/static/199');
$controller->execute();
// and so on up to /static/999 route
// non static routes
$router = RouteGenerator::generateJoomlaNonStaticRoutes(1000);
$controller = $router->getController('/param/1/0');
$controller->execute();
$controller = $router->getController('/param/1/99');
$controller->execute();
$controller = $router->getController('/param/1/199');
$controller->execute();
// and so on up to /param/1/999 route

OK What do we have?

The first case + static routes

+------------------------------------+---------+
| benchmark | diff |
+------------------------------------+---------+
| CoffeeSingleRequestStaticBench | 30.05x |
| DVKSingleRequestStaticBench | 18.41x |
| HoaSingleRequestStaticBench | 40.34x |
| IBSingleRequestStaticBench | 82.37x |
| JoomlaSingleRequestStaticBench | 18.57x |
| MezonSingleRequestStaticBench | 6.05x |
| MiladSingleRequestStaticBench | 18.73x |
| PeceeSingleRequestStaticBench | 24.78x |
| PowerSingleRequestStaticBench | 13.77x |
| SteampixelSingleRequestStaticBench | 135.12x |
| ToroSingleRequestStaticBench | 1.00x |
| ZaphpaSingleRequestStaticBench | 21.83x |
+------------------------------------+---------+

The first case + non-static routes

+-----------------------------------+--------+
| benchmark | diff |
+-----------------------------------+--------+
| CoffeeSingleRequestParamBench | 5.38x |
| DVKSingleRequestParamBench | 2.78x |
| HoaSingleRequestParamBench | 4.20x |
| IBSingleRequestParamBench | 13.25x |
| JoomlaSingleRequestParamBench | 3.32x |
| MezonSingleRequestParamBench | 11.22x |
| MiladSingleRequestParamBench | 3.38x |
| PeceeSingleRequestParamBench | 7.25x |
| PowerSingleRequestParamBench | 2.28x |
| SteampixelSingleRequestParamBench | 22.32x |
| ToroSingleRequestParamBench | 1.00x |
| ZaphpaSingleRequestParamBench | 4.66x |
+-----------------------------------+--------+

The second case + static routes

+----------------------------+-----------+
| benchmark | diff |
+----------------------------+-----------+
| CoffeeReactStaticBench | 277.63x |
| DVKReactStaticBench | 460.24x |
| HoaReactStaticBench | 146.80x |
| IBReactStaticBench | 1,362.26x |
| JoomlaReactStaticBench | 186.80x |
| MezonReactStaticBench | 1.00x |
| MiladReactStaticBench | 621.50x |
| PeceeReactStaticBench | 760.66x |
| PowerReactStaticBench | 518.41x |
| SteampixelReactStaticBench | 8,955.72x |
| ToroReactStaticBench | 19.12x |
| ZaphpaReactStaticBench | 536.46x |
+----------------------------+-----------+

The second case + non-static routes

+---------------------------+---------+
| benchmark | diff |
+---------------------------+---------+
| CoffeeReactParamBench | 15.15x |
| DVKReactParamBench | 11.86x |
| HoaReactParamBench | 4.59x |
| IBReactParamBench | 29.10x |
| JoomlaReactParamBench | 4.44x |
| MezonReactParamBench | 1.00x |
| MiladReactParamBench | 20.14x |
| PeceeReactParamBench | 41.78x |
| PowerReactParamBench | 13.73x |
| SteampixelReactParamBench | 243.13x |
| ToroReactParamBench | 6.94x |
| ZaphpaReactParamBench | 19.28x |
+---------------------------+---------+

As you can see almost in all cases Mezon Router is faster that Joomla 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

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

React Monorepo Using Yarn Workspaces Only (No Lerna)

Run cypress tests individually in VS code without any extensions.

Putting Super Authors to Work

Send User Analytics Data via a WebSocket to a React App (optional) with Serverless — for free…

Node Interview Questions 2021

Blog Post Week One Javascript

https://bitcoinist.com/author/danb/

Lessons I’ve learned after a year of using TypeScript

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Dodonov Alexey

Dodonov Alexey

php developer

More from Medium

pre_fetch_count in common cases in PHP

Common problems faced by PHP developers in consuming an AMQP message

Go — If/Else, Switch, and For loop

Back to Laravel Homestead from Sail / Docker