New benchmark: Mezon Router is up to 567 times faster than Zaphpa 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::generateZaphpaStaticRoutes(1000);
$router->route();
$_SERVER['REQUEST_METHOD'] = 'GET';
$_SERVER['REQUEST_URI'] = '/static/99';
$router = RouteGenerator::generateZaphpaStaticRoutes(1000);
$router->route();
$_SERVER['REQUEST_METHOD'] = 'GET';
$_SERVER['REQUEST_URI'] = '/static/199';
$router = RouteGenerator::generateZaphpaStaticRoutes(1000);
$router->route();
// and so on up to /static/999 route
// non static routes
$_SERVER['REQUEST_METHOD'] = 'GET';
$_SERVER['REQUEST_URI'] = '/param/0/1/';
$router = RouteGenerator::generateZaphpaNonStaticRoutes(1000);
$router->route();
$_SERVER['REQUEST_METHOD'] = 'GET';
$_SERVER['REQUEST_URI'] = '/param/99/1/';
$router = RouteGenerator::generateZaphpaNonStaticRoutes(1000);
$router->route();
$_SERVER['REQUEST_METHOD'] = 'GET';
$_SERVER['REQUEST_URI'] = '/param/199/1/';
$router = RouteGenerator::generateZaphpaNonStaticRoutes(1000);
$router->route();
// and so on up to /param/999/1 route

The second case

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

OK What do we have?

The first case + static routes

+------------------------------------+--------+
| benchmark | diff |
+------------------------------------+--------+
| CoffeeSingleRequestStaticBench | 11.74x |
| DVKSingleRequestStaticBench | 7.05x |
| HoaSingleRequestStaticBench | 12.72x |
| IBSingleRequestStaticBench | 34.88x |
| MezonSingleRequestStaticBench | 2.56x |
| MiladSingleRequestStaticBench | 8.28x |
| PeceeSingleRequestStaticBench | 10.62x |
| PowerSingleRequestStaticBench | 5.80x |
| SteampixelSingleRequestStaticBench | 66.50x |
| ToroSingleRequestStaticBench | 1.00x |
| ZaphpaSingleRequestStaticBench | 17.06x |
+------------------------------------+--------+

The first case + non-static routes

+-----------------------------------+--------+
| benchmark | diff |
+-----------------------------------+--------+
| CoffeeSingleRequestParamBench | 3.72x |
| DVKSingleRequestParamBench | 1.99x |
| HoaSingleRequestParamBench | 2.78x |
| IBSingleRequestParamBench | 8.75x |
| MezonSingleRequestParamBench | 8.42x |
| MiladSingleRequestParamBench | 2.13x |
| PeceeSingleRequestParamBench | 4.55x |
| PowerSingleRequestParamBench | 1.36x |
| SteampixelSingleRequestParamBench | 19.92x |
| ToroSingleRequestParamBench | 1.00x |
| ZaphpaSingleRequestParamBench | 4.94x |
+-----------------------------------+--------+

The second case + static routes

+----------------------------+------------+
| benchmark | diff |
+----------------------------+------------+
| CoffeeReactStaticBench | 381.38x |
| DVKReactStaticBench | 492.29x |
| HoaReactStaticBench | 164.61x |
| IBReactStaticBench | 1,219.60x |
| MezonReactStaticBench | 1.00x |
| MiladReactStaticBench | 799.16x |
| PeceeReactStaticBench | 896.31x |
| PowerReactStaticBench | 791.97x |
| SteampixelReactStaticBench | 11,353.55x |
| ToroReactStaticBench | 17.73x |
| ZaphpaReactStaticBench | 566.75x |
+----------------------------+------------+

The second case + non-static routes

+---------------------------+---------+
| benchmark | diff |
+---------------------------+---------+
| CoffeeReactParamBench | 7.94x |
| DVKReactParamBench | 12.29x |
| HoaReactParamBench | 3.93x |
| IBReactParamBench | 33.08x |
| MezonReactParamBench | 1.00x |
| MiladReactParamBench | 20.17x |
| PeceeReactParamBench | 53.15x |
| PowerReactParamBench | 32.70x |
| SteampixelReactParamBench | 319.20x |
| ToroReactParamBench | 9.86x |
| ZaphpaReactParamBench | 23.99x |
+---------------------------+---------+

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

What’s a Dynamic framework

Singleton Design Pattern | සිංහලෙන්

How To Acquire Airports Database In 2022

COVID-19 restrictions to shut down Michigan colleges

WSO2 Identity Analytics

Python Web Scraping Part: 4

Working With YAML File Format in Python

Zero Downtime Deployment of BusinessWorks Container Edition with Kubernetes — Part 5

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

octoDNS, GitHub Actions, Cloudflare & Digital Ocean — Redundant, Multi-cloud DNS hosting for free

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

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

Real-Time Twitter Bot that responds with James Webb’s telescope telemetry

Curved rocket trail on dusk sky, starting on earth and ending in cloudless sky