New benchmark: Mezon Router is up to 931 times faster then Rareloop Router

Hello people! Since the previous benchmark Mezon Router have got a bugfix wich increases productivity. New benchmark results can be seen on this article.

As usual we have two cases:

  1. http server accepts request, launches php script, which handles this request, and then all script data uploads 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';
$router = \Mezon\Benchmark\RouteGenerator::generateRareloopStaticRoutes(1000);
$startTime = microtime(true);
for ($i = 0; $i < \Mezon\Benchmark\Base::$iterationsAmount; $i ++) {
$_SERVER['REQUEST_URI'] = '/static/' . rand(0, 1000 - 1);
$request = Laminas\Diactoros\ServerRequestFactory::fromGlobals();
$router->match($request);
}
return microtime(true) - $startTime;
// non-static routes
$_SERVER['REQUEST_METHOD'] = 'GET';
$router = \Mezon\Benchmark\RouteGenerator::generateRareloopNonStaticRoutes(1000);
$startTime = microtime(true);
for ($i = 0; $i < \Mezon\Benchmark\Base::$iterationsAmount; $i ++) {
$_SERVER['REQUEST_URI'] = '/param/' . rand(0, 1000 - 1) . '/1';
$request = Laminas\Diactoros\ServerRequestFactory::fromGlobals();
$router->match($request);
}
return microtime(true) - $startTime;

The second case

// static routes
$_SERVER['REQUEST_METHOD'] = 'GET';
$router = \Mezon\Benchmark\RouteGenerator::generateRareloopStaticRoutes(1000);
$startTime = microtime(true);
for ($i = 0; $i < \Mezon\Benchmark\Base::$iterationsAmount; $i ++) {
$_SERVER['REQUEST_URI'] = '/static/' . rand(0, 1000 - 1);
$request = Laminas\Diactoros\ServerRequestFactory::fromGlobals();
$router->match($request);
}
return microtime(true) - $startTime;
// non-static routes
$_SERVER['REQUEST_METHOD'] = 'GET';
$router = \Mezon\Benchmark\RouteGenerator::generateRareloopNonStaticRoutes(1000);
$startTime = microtime(true);
for ($i = 0; $i < \Mezon\Benchmark\Base::$iterationsAmount; $i ++) {
$_SERVER['REQUEST_URI'] = '/param/' . rand(0, 1000 - 1) . '/1';
$request = Laminas\Diactoros\ServerRequestFactory::fromGlobals();
$router->match($request);
}
return microtime(true) - $startTime;

Results

As you can see Mezon router is in all cases is faster then Rareloop Route.

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

Setup OpenCV-DNN module with CUDA backend support (For Linux)

How to develop a VS Code Extension Step By Step — Translator Helper

Repository Pattern with AutoMapper in .Net Core

My Journey to MongoDB: C100DEV Certification

Everything is Object in Python

The Importance of Identifying a Product Goal

First Look: New Nitro Features Come to Your Web Browser

With @VSTMEX, EARNING BITCOIN is as easy as completing mini-tasks!

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 create an automated pipeline for deploy with Symfony 5 and DigitalOcean App Platform

Tutorial: Docker PHP Development setup for the generation of TikTok attention span developers

Example Dockerfile

How to Install and Configure LAMP stack on Arch Linux

How to enable PCNTL in Apache