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

The second case

// static routes
$_SERVER['REQUEST_METHOD'] = 'GET';
$_SERVER['REQUEST_URI'] = '/static/0';
RouteGenerator::generateMacawStaticRoutes(1000);
Macaw::dispatch();
$_SERVER['REQUEST_METHOD'] = 'GET';
$_SERVER['REQUEST_URI'] = '/static/99';
Macaw::dispatch();
$_SERVER['REQUEST_METHOD'] = 'GET';
$_SERVER['REQUEST_URI'] = '/static/199';
Macaw::dispatch();
// and so on up to /static/999 route
// non static routes
$_SERVER['REQUEST_METHOD'] = 'GET';
$_SERVER['REQUEST_URI'] = '/param/0/1';
RouteGenerator::generateMacawNonStaticRoutes(1000);
Macaw::dispatch();
$_SERVER['REQUEST_METHOD'] = 'GET';
$_SERVER['REQUEST_URI'] = '/param/99/1';
Macaw::dispatch();
$_SERVER['REQUEST_METHOD'] = 'GET';
$_SERVER['REQUEST_URI'] = '/param/199/1';
Macaw::dispatch();
// and so on up to /param/1/999 route

OK What do we have?

The first case + static routes

+------------------------------------+---------+
| benchmark | diff |
+------------------------------------+---------+
| CoffeeSingleRequestStaticBench | 26.88x |
| DVKSingleRequestStaticBench | 16.64x |
| HoaSingleRequestStaticBench | 28.71x |
| IBSingleRequestStaticBench | 81.65x |
| JoomlaSingleRequestStaticBench | 19.01x |
| LeafSingleRequestStaticBench | 19.55x |
| MacawSingleRequestStaticBench | 10.46x |
| MezonSingleRequestStaticBench | 6.23x |
| MiladSingleRequestStaticBench | 19.97x |
| PeceeSingleRequestStaticBench | 25.55x |
| PowerSingleRequestStaticBench | 13.61x |
| SteampixelSingleRequestStaticBench | 133.90x |
| TetoSingleRequestStaticBench | 28.05x |
| ToroSingleRequestStaticBench | 1.00x |
| ZaphpaSingleRequestStaticBench | 22.39x |
+------------------------------------+---------+

The first case + non-static routes

+-----------------------------------+--------+
| benchmark | diff |
+-----------------------------------+--------+
| CoffeeSingleRequestParamBench | 2.54x |
| DVKSingleRequestParamBench | 1.45x |
| HoaSingleRequestParamBench | 2.28x |
| IBSingleRequestParamBench | 7.39x |
| JoomlaSingleRequestParamBench | 1.91x |
| LeafSingleRequestParamBench | 1.65x |
| MacawSingleRequestParamBench | 1.56x |
| MezonSingleRequestParamBench | 7.45x |
| MiladSingleRequestParamBench | 1.74x |
| PeceeSingleRequestParamBench | 3.63x |
| PowerSingleRequestParamBench | 1.00x |
| SteampixelSingleRequestParamBench | 11.10x |
| TetoSingleRequestParamBench | 3.50x |
| ToroSingleRequestParamBench | 1.20x |
| ZaphpaSingleRequestParamBench | 2.32x |
+-----------------------------------+--------+

The second case + static routes

+----------------------------+------------+
| benchmark | diff |
+----------------------------+------------+
| CoffeeReactStaticBench | 533.63x |
| DVKReactStaticBench | 628.79x |
| HoaReactStaticBench | 214.93x |
| IBReactStaticBench | 1,583.97x |
| JoomlaReactStaticBench | 324.70x |
| LeafReactStaticBench | 488.96x |
| MacawReactStaticBench | 235.78x |
| MezonReactStaticBench | 1.00x |
| MiladReactStaticBench | 929.66x |
| PeceeReactStaticBench | 1,172.75x |
| PowerReactStaticBench | 918.76x |
| SteampixelReactStaticBench | 13,719.70x |
| TetoReactStaticBench | 246.28x |
| ToroReactStaticBench | 24.08x |
| ZaphpaReactStaticBench | 774.50x |
+----------------------------+------------+

The second case + non-static routes

+---------------------------+---------+
| benchmark | diff |
+---------------------------+---------+
| CoffeeReactParamBench | 8.59x |
| DVKReactParamBench | 11.06x |
| HoaReactParamBench | 2.84x |
| IBReactParamBench | 27.03x |
| JoomlaReactParamBench | 3.01x |
| LeafReactParamBench | 7.51x |
| MacawReactParamBench | 10.91x |
| MezonReactParamBench | 1.00x |
| MiladReactParamBench | 16.60x |
| PeceeReactParamBench | 35.14x |
| PowerReactParamBench | 12.41x |
| SteampixelReactParamBench | 172.21x |
| TetoReactParamBench | 8.28x |
| ToroReactParamBench | 9.33x |
| ZaphpaReactParamBench | 27.61x |
+---------------------------+---------+

As you can see in half of all cases Mezon Router is faster than Macaw 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 is for loop in Kotlin?

{UPDATE} Sudoku : Cartoon Hack Free Resources Generator

Make your existing solution tastier with serverless salt: feasibility

leetcode 516. Longest Palindromic Subsequence

Interning on Slack’s Product Security Team

From the Genesis to The Genesys: My Journey in the Tech World

HyperDao - a DAO based IDO launchpad Coming Soon❗️🔥 Offering Unparalleled: - Transparency ⭐️ …

Understanding Interfaces & Abstract Classes for Beginners

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

GSoC 2015 — Moorsp plugin for Moodle — Wrap Up

Setup redis and sidekiq service

Configure Nagios 4 with Nginx on Ubuntu 20.04

Install Nagios 4 + Nginx + Ubuntu 20.04

Listening process and ports on Mac OS