New benchmark: Mezon Router is up to 922 times faster than MiladRahimi Router

Dodonov Alexey
3 min readJun 2, 2021

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::generateMiladRahimiStaticRoutes(1000);
$router->dispatch();
$_SERVER['REQUEST_METHOD'] = 'GET';
$_SERVER['REQUEST_URI'] = '/static/99';
$router = RouteGenerator::generateMiladRahimiStaticRoutes(1000);
$router->dispatch();
// and so on up to /static/999 route
// non static routes
$_SERVER['REQUEST_METHOD'] = 'GET';
$_SERVER['REQUEST_URI'] = '/param/0/1/';
$router = RouteGenerator::generateMiladRahimiNonStaticRoutes(1000);
$router->dispatch();
$_SERVER['REQUEST_METHOD'] = 'GET';
$_SERVER['REQUEST_URI'] = '/param/99/1/';
$router = RouteGenerator::generateMiladRahimiNonStaticRoutes(1000);
$router->dispatch();
// and so on up to /param/999/1 route

The second case

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

OK What do we have?

The first case + static routes

+------------------------------------+--------+
| benchmark | diff |
+------------------------------------+--------+
| CoffeeSingleRequestStaticBench | 6.15x |
| DVKSingleRequestStaticBench | 2.70x |
| HoaSingleRequestStaticBench | 5.98x |
| IBSingleRequestStaticBench | 13.70x |
| MezonSingleRequestStaticBench | 1.00x |
| MiladSingleRequestStaticBench | 3.10x |
| PeceeSingleRequestStaticBench | 6.33x |
| SteampixelSingleRequestStaticBench | 28.83x |
+------------------------------------+--------+

The first case + non-static routes

+-----------------------------------+-------+
| benchmark | diff |
+-----------------------------------+-------+
| CoffeeSingleRequestParamBench | 1.83x |
| DVKSingleRequestParamBench | 1.31x |
| HoaSingleRequestParamBench | 1.74x |
| IBSingleRequestParamBench | 3.82x |
| MezonSingleRequestParamBench | 3.61x |
| MiladSingleRequestParamBench | 1.00x |
| PeceeSingleRequestParamBench | 2.12x |
| SteampixelSingleRequestParamBench | 6.89x |
+-----------------------------------+-------+

The second case + static routes

+----------------------------+------------+
| benchmark | diff |
+----------------------------+------------+
| CoffeeReactStaticBench | 433.58x |
| DVKReactStaticBench | 621.24x |
| HoaReactStaticBench | 210.54x |
| IBReactStaticBench | 1,563.46x |
| MezonReactStaticBench | 1.00x |
| MiladReactStaticBench | 922.58x |
| PeceeReactStaticBench | 1,212.65x |
| SteampixelReactStaticBench | 12,559.46x |
+----------------------------+------------+

The second case + non-static routes

+---------------------------+---------+
| benchmark | diff |
+---------------------------+---------+
| CoffeeReactParamBench | 15.60x |
| DVKReactParamBench | 13.02x |
| HoaReactParamBench | 3.51x |
| IBReactParamBench | 31.04x |
| MezonReactParamBench | 1.00x |
| MiladReactParamBench | 24.54x |
| PeceeReactParamBench | 41.41x |
| SteampixelReactParamBench | 224.15x |
+---------------------------+---------+

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 )

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

No responses yet

Write a response