New benchmark: Mezon Router is up to 658 times faster than Coffee 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::generatePeceeStaticRoutes(1000);
$router->getRequest()->setUrl(new Url('/static/0'));
$router->getRequest()->setMethod('get');
$router->start();
$router = RouteGenerator::generatePeceeStaticRoutes(1000);
$router->getRequest()->setUrl(new Url('/static/99'));
$router->getRequest()->setMethod('get');
$router->start();
$router = RouteGenerator::generatePeceeStaticRoutes(1000);
$router->getRequest()->setUrl(new Url('/static/199'));
$router->getRequest()->setMethod('get');
$router->start();
// and so on up to '/static/999'

Non-static routes:

$router = RouteGenerator::generatePeceeNonStaticRoutes(1000);
$router->getRequest()->setUrl(new Url('/param/0/1'));
$router->getRequest()->setMethod('get');
$router->start();
$router = RouteGenerator::generatePeceeNonStaticRoutes(1000);
$router->getRequest()->setUrl(new Url('/param/99/1'));
$router->getRequest()->setMethod('get');
$router->start();
$router = RouteGenerator::generatePeceeNonStaticRoutes(1000);
$router->getRequest()->setUrl(new Url('/param/199/1'));
$router->getRequest()->setMethod('get');
$router->start();
// and so on up to '/param/999/1'

The second case

$router = RouteGenerator::generatePeceeStaticRoutes(1000);$router->getRequest()->setUrl(new Url('/static/0'));
$router->getRequest()->setMethod('get');
$router->start();
$router->getRequest()->setUrl(new Url('/static/99'));
$router->getRequest()->setMethod('get');
$router->start();
$router->getRequest()->setUrl(new Url('/static/199'));
$router->getRequest()->setMethod('get');
$router->start();
// and so on up to '/static/999'

Non-static routes:

$router = RouteGenerator::generatePeceeNonStaticRoutes(1000);
$router->getRequest()->setUrl(new Url('/param/0/1'));
$router->getRequest()->setMethod('get');
$router->start();
$router->getRequest()->setUrl(new Url('/param/99/1'));
$router->getRequest()->setMethod('get');
$router->start();
$router->getRequest()->setUrl(new Url('/param/199/1'));
$router->getRequest()->setMethod('get');
$router->start();
// and so on up to '/param/999/1'

OK What do we have?

The first case + static routes

+-------------------------------+-------+
| benchmark | diff |
+-------------------------------+-------+
| DVKSingleRequestStaticBench | 3.19x |
| HoaSingleRequestStaticBench | 5.16x |
| MezonSingleRequestStaticBench | 1.00x |
| PeceeSingleRequestStaticBench | 5.43x |
+-------------------------------+-------+

The first case + non-static routes

+------------------------------+-------+
| benchmark | diff |
+------------------------------+-------+
| DVKSingleRequestParamBench | 1.00x |
| HoaSingleRequestParamBench | 1.59x |
| MezonSingleRequestParamBench | 5.21x |
| PeceeSingleRequestParamBench | 2.26x |
+------------------------------+-------+

The second case + static routes

+-----------------------+---------+
| benchmark | diff |
+-----------------------+---------+
| DVKReactStaticBench | 272.60x |
| HoaReactStaticBench | 132.07x |
| MezonReactStaticBench | 1.00x |
| PeceeReactStaticBench | 463.60x |
+-----------------------+---------+

The second case + non-static routes

+----------------------+--------+
| benchmark | diff |
+----------------------+--------+
| DVKReactParamBench | 6.82x |
| HoaReactParamBench | 1.65x |
| MezonReactParamBench | 1.00x |
| PeceeReactParamBench | 28.16x |
+----------------------+--------+

What’s next?

More info can be found in my GitHub account

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

DADI Helper Bot

Typescript dynamic type with any

Test-Driven Development With The oclif Testing Library: Part Two

Using your local .npmrc inside a VS Code development container

Node Knockout 2017

React Devstack

React analysis for beginners

You definitely should be using Suspense in React — code splitting and preloading

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

Lets Use Hashicorp Packer for creating LAMP Stack (Part 1 — Creating AWS AMI)

Listening process and ports on Mac OS

Configure Nagios 4 with Nginx on Ubuntu 20.04

Install Nagios 4 + Nginx + Ubuntu 20.04

Hello Rancher Desktop!!