New benchmark: Mezon Router is up to 128 times faster than Teto 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
$router = RouteGenerator::generateTetoStaticRoutes(1000);
$router->match('GET', '/static/0');
$router = RouteGenerator::generateTetoStaticRoutes(1000);
$router->match('GET', '/static/99');
$router = RouteGenerator::generateTetoStaticRoutes(1000);
$router->match('GET', '/static/199');
// and so on up to /static/999 route
// non static routes
$router = RouteGenerator::generateTetoNonStaticRoutes(1000);
$router->match('GET', '/param/0/1');
$router = RouteGenerator::generateTetoNonStaticRoutes(1000);
$router->match('GET', '/param/99/1');
$router = RouteGenerator::generateTetoNonStaticRoutes(1000);
$router->match('GET', '/param/199/1');
// and so on up to /param/999/1 route

The second case

// static routes
$router = RouteGenerator::generateTetoStaticRoutes(1000);
$router->match('GET', '/static/0');$router->match('GET', '/static/99');$router->match('GET', '/static/199');
// and so on up to /static/999 route
// non static routes
$router = RouteGenerator::generateTetoNonStaticRoutes(1000);
$router->match('GET', '/param/0/1');$router->match('GET', '/param/99/1');$router->match('GET', '/param/199/1');
// and so on up to /param/1/999 route

OK What do we have?

The first case + static routes

+------------------------------------+---------+
| benchmark | diff |
+------------------------------------+---------+
| CoffeeSingleRequestStaticBench | 25.84x |
| DVKSingleRequestStaticBench | 16.41x |
| HoaSingleRequestStaticBench | 31.86x |
| IBSingleRequestStaticBench | 73.64x |
| JoomlaSingleRequestStaticBench | 18.25x |
| MezonSingleRequestStaticBench | 5.63x |
| MiladSingleRequestStaticBench | 17.34x |
| PeceeSingleRequestStaticBench | 27.61x |
| PowerSingleRequestStaticBench | 11.30x |
| SteampixelSingleRequestStaticBench | 128.69x |
| TetoSingleRequestStaticBench | 22.09x |
| ToroSingleRequestStaticBench | 1.00x |
| ZaphpaSingleRequestStaticBench | 18.02x |
+------------------------------------+---------+

The first case + non-static routes

+-----------------------------------+--------+
| benchmark | diff |
+-----------------------------------+--------+
| CoffeeSingleRequestParamBench | 5.45x |
| DVKSingleRequestParamBench | 2.92x |
| HoaSingleRequestParamBench | 5.34x |
| IBSingleRequestParamBench | 15.57x |
| JoomlaSingleRequestParamBench | 6.22x |
| MezonSingleRequestParamBench | 15.81x |
| MiladSingleRequestParamBench | 4.34x |
| PeceeSingleRequestParamBench | 9.13x |
| PowerSingleRequestParamBench | 2.21x |
| SteampixelSingleRequestParamBench | 27.19x |
| TetoSingleRequestParamBench | 5.42x |
| ToroSingleRequestParamBench | 1.00x |
| ZaphpaSingleRequestParamBench | 5.71x |
+-----------------------------------+--------+

The second case + static routes

+----------------------------+------------+
| benchmark | diff |
+----------------------------+------------+
| CoffeeReactStaticBench | 476.98x |
| DVKReactStaticBench | 387.95x |
| HoaReactStaticBench | 116.19x |
| IBReactStaticBench | 917.11x |
| JoomlaReactStaticBench | 255.44x |
| MezonReactStaticBench | 1.00x |
| MiladReactStaticBench | 830.45x |
| PeceeReactStaticBench | 1,113.20x |
| PowerReactStaticBench | 880.13x |
| SteampixelReactStaticBench | 10,413.11x |
| TetoReactStaticBench | 128.41x |
| ToroReactStaticBench | 14.57x |
| ZaphpaReactStaticBench | 407.74x |
+----------------------------+------------+

The second case + non-static routes

+---------------------------+---------+
| benchmark | diff |
+---------------------------+---------+
| CoffeeReactParamBench | 8.17x |
| DVKReactParamBench | 12.40x |
| HoaReactParamBench | 3.38x |
| IBReactParamBench | 31.61x |
| JoomlaReactParamBench | 3.78x |
| MezonReactParamBench | 1.00x |
| MiladReactParamBench | 19.35x |
| PeceeReactParamBench | 41.94x |
| PowerReactParamBench | 15.34x |
| SteampixelReactParamBench | 210.30x |
| TetoReactParamBench | 9.98x |
| ToroReactParamBench | 8.51x |
| ZaphpaReactParamBench | 22.06x |
+---------------------------+---------+

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

Key Types of Website Testing and How to Test Your Website

How can Manual Testers survive Automation?

Learning AMP: Parallax Scrolling Effect — AMPire.city

DevOps with GitHub — Part 2: Building and Publishing Packages with GitHub Actions

The (probable) end of the front-end profession as you know it

Understand the problem statement to optimize your code

Optimizing AWS Cost — What Are The Best Practices

Xcode — How to fix ‘NSUnknownKeyException’, reason: … this class is not key value coding-compliant…

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

chef-js: http(s) node webserver CLI

Pagination In Lighthouse GraphQL

Fix Windows 10/11 Icons Not Showing Up / Working as Expected

Common problems faced by PHP developers in consuming an AMQP message