New benchmark: Mezon Router is up to 922 times faster than MiladRahimi 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::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 )

--

--

--

php developer

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

Recommended from Medium

CS 373 Spring 2021 (Week 10): Prateeka Kodali

How to install Python3 with OpenCV4

Why Using An API To Categorise Text

Encode x Internet Computer Hackathon Finale Prizewinners and Summary

Explain it like I’m 5: The three phases of observability

PIC 18 TMR1 As Counter

Storing Databases

Improve git command under WSL2

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

Configure Nagios 4 with Nginx on Ubuntu 20.04

Install Nagios 4 + Nginx + Ubuntu 20.04

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

How to integrate ASP.NET Core Web to CloudWatch on AWS Beanstalk?

Understanding TLS Cipher Suites