New benchmark: Mezon Router VS Power 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::generatePowerStaticRoutes(1000);
$request = ServerRequestFactory::fromGlobals();
$router->start($request, new Response());
$_SERVER['REQUEST_METHOD'] = 'GET';
$_SERVER['REQUEST_URI'] = '/static/99';
$router = RouteGenerator::generatePowerStaticRoutes(1000);
$request = ServerRequestFactory::fromGlobals();
$router->start($request, new Response());
$_SERVER['REQUEST_METHOD'] = 'GET';
$_SERVER['REQUEST_URI'] = '/static/199';
$router = RouteGenerator::generatePowerStaticRoutes(1000);
$request = ServerRequestFactory::fromGlobals();
$router->start($request, new Response());
// and so on up to /static/999 route
// non static routes
$_SERVER['REQUEST_METHOD'] = 'GET';
$_SERVER['REQUEST_URI'] = '/param/0/1/';
$router = RouteGenerator::generatePowerNonStaticRoutes(1000);
$request = ServerRequestFactory::fromGlobals();
$router->start($request, new Response());
$_SERVER['REQUEST_METHOD'] = 'GET';
$_SERVER['REQUEST_URI'] = '/param/99/1/';
$router = RouteGenerator::generatePowerNonStaticRoutes(1000);
$request = ServerRequestFactory::fromGlobals();
$router->start($request, new Response());
$_SERVER['REQUEST_METHOD'] = 'GET';
$_SERVER['REQUEST_URI'] = '/param/199/1/';
$router = RouteGenerator::generatePowerNonStaticRoutes(1000);
$request = ServerRequestFactory::fromGlobals();
$router->start($request, new Response());
// and so on up to /param/999/1 route

The second case

// static routes
$router = RouteGenerator::generatePowerStaticRoutes(1000);
$_SERVER['REQUEST_METHOD'] = 'GET';
$_SERVER['REQUEST_URI'] = '/static/0';
$request = ServerRequestFactory::fromGlobals();
$router->start($request, new Response());
$_SERVER['REQUEST_METHOD'] = 'GET';
$_SERVER['REQUEST_URI'] = '/static/99';
$request = ServerRequestFactory::fromGlobals();
$router->start($request, new Response());
$_SERVER['REQUEST_METHOD'] = 'GET';
$_SERVER['REQUEST_URI'] = '/static/199';
$request = ServerRequestFactory::fromGlobals();
$router->start($request, new Response());
// and so on up to /static/999 route
// non static routes
$router = RouteGenerator::generatePowerNonStaticRoutes(1000);
$_SERVER['REQUEST_METHOD'] = 'GET';
$_SERVER['REQUEST_URI'] = '/param/0/1/';
$request = ServerRequestFactory::fromGlobals();
$router->start($request, new Response());
$_SERVER['REQUEST_METHOD'] = 'GET';
$_SERVER['REQUEST_URI'] = '/param/99/1/';
$request = ServerRequestFactory::fromGlobals();
$router->start($request, new Response());
$_SERVER['REQUEST_METHOD'] = 'GET';
$_SERVER['REQUEST_URI'] = '/param/199/1/';
$request = ServerRequestFactory::fromGlobals();
$router->start($request, new Response());
// and so on up to /param/999/1 route

OK What do we have?

The first case + static routes

+------------------------------------+---------+
| benchmark | diff |
+------------------------------------+---------+
| CoffeeSingleRequestStaticBench | 48.66x |
| DVKSingleRequestStaticBench | 15.43x |
| HoaSingleRequestStaticBench | 27.23x |
| IBSingleRequestStaticBench | 75.39x |
| MezonSingleRequestStaticBench | 5.41x |
| MiladSingleRequestStaticBench | 17.78x |
| PeceeSingleRequestStaticBench | 21.53x |
| PowerSingleRequestStaticBench | 11.65x |
| SteampixelSingleRequestStaticBench | 121.77x |
| ToroSingleRequestStaticBench | 1.00x |
+------------------------------------+---------+

The first case + non-static routes

+-----------------------------------+--------+
| benchmark | diff |
+-----------------------------------+--------+
| CoffeeSingleRequestParamBench | 4.85x |
| DVKSingleRequestParamBench | 2.72x |
| HoaSingleRequestParamBench | 4.23x |
| IBSingleRequestParamBench | 13.36x |
| MezonSingleRequestParamBench | 11.41x |
| MiladSingleRequestParamBench | 3.28x |
| PeceeSingleRequestParamBench | 7.65x |
| PowerSingleRequestParamBench | 2.59x |
| SteampixelSingleRequestParamBench | 31.56x |
| ToroSingleRequestParamBench | 1.00x |
+-----------------------------------+--------+

The second case + static routes

+----------------------------+------------+
| benchmark | diff |
+----------------------------+------------+
| CoffeeReactStaticBench | 410.30x |
| DVKReactStaticBench | 525.23x |
| HoaReactStaticBench | 176.23x |
| IBReactStaticBench | 1,279.88x |
| MezonReactStaticBench | 1.00x |
| MiladReactStaticBench | 791.48x |
| PeceeReactStaticBench | 981.11x |
| PowerReactStaticBench | 760.63x |
| SteampixelReactStaticBench | 16,879.41x |
| ToroReactStaticBench | 18.59x |
+----------------------------+------------+

The second case + non-static routes

+---------------------------+---------+
| benchmark | diff |
+---------------------------+---------+
| CoffeeReactParamBench | 6.19x |
| DVKReactParamBench | 12.34x |
| HoaReactParamBench | 3.33x |
| IBReactParamBench | 39.52x |
| MezonReactParamBench | 1.00x |
| MiladReactParamBench | 19.11x |
| PeceeReactParamBench | 35.80x |
| PowerReactParamBench | 11.59x |
| SteampixelReactParamBench | 181.20x |
| ToroReactParamBench | 5.93x |
+---------------------------+---------+

As you can see in some cases Power Router is the fastest router, in some cases it is not, but still shows good results.

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

14 Twitter Accounts to Follow as a Web Developer

Woman curiously looking at a screen in the kitchen

Top Node IDEs for Developing Node.js Apps In 2020

Data Structures — Part 1 — Queues + How to Implement

queue

Get a magnifying glass loader with the click of a button.

Creating HTTP Endpoints in NestJS

Excel download in Nuxtjs/Vuejs

Get a JavaScript Breakout game at the click of a button

Exploring more about reducers, pure functions,side-effects ,useEffect() ,async calls and context..!

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

How to monitor disk space on EC2

Fix “413 request entity too large” Nginx error on AWS Elastic Beanstalk via EBS Configuration

Building a “People who bought this item but also bought” recommendation engine.

Rough process flow of how the recommended products are generated.

About Cloudflare proxy status and Let’s encrypt and too many redirects error