Real life comparison of Symfony router and Mezon router. Part 2

Dodonov Alexey
2 min readSep 17, 2020

--

Intro

Hi all! Since the last article I have got some feedback. And the time has come to improve benchmark according to this feedback.

Improvements

The author of the CompiledUrlMatcher Nikolas Grekas pointed on mistake in this case:

for ($i = 0; $i < \Mezon\Benchmark\Base::$iterationsAmount; $i ++) {
$staticRoutes = \Mezon\Benchmark\RouteGenerator::generateSymfonyStaticRoutes(1000);
$dumper = new CompiledUrlMatcherDumper($staticRoutes); $requestContext = new RequestContext();
$requestContext->fromRequest(Request::createFromGlobals());
$staticMatcher = new CompiledUrlMatcher($dumper->getCompiledRoutes(), $requestContext);
$staticMatcher->match('/static/' . rand(0, ROUTES_AMOUNT - 1))['controller']();
}

He have told that $dumper->getCompiledRoutes() should not be called in array. Very reasonable. So I have changed the benchmark and now it looks like this:

// before the benchmark we shall compile routes and store them into cache
$staticRoutes = \Mezon\Benchmark\RouteGenerator::generateSymfonyStaticRoutes(1000);
$dumperStatic = new CompiledUrlMatcherDumper($staticRoutes);
file_put_contents(
__DIR__ . '/../../../cache/static-cache.php',
'<?php return ' . var_export($dumperStatic->getCompiledRoutes(), true) . ';');

And then we shall use this cache in the case:

for ($i = 0; $i < \Mezon\Benchmark\Base::$iterationsAmount; $i ++) {
$requestContext = new RequestContext();
$requestContext->fromRequest(Request::createFromGlobals());
$compiledRoutes = require __DIR__ . '/../../../cache/static-cache.php'; $staticMatcher = new CompiledUrlMatcher($compiledRoutes, $requestContext);
$staticMatcher->match('/static/' . rand(0, \Mezon\Benchmark\Base::$iterationsAmount - 1))['controller']();
}

And what are the results? )

  1. Mezon router is almost in all cases faster then Symfony’s default UrlMatcher;
  2. But if you agree to dig into Symfony’s CompiledUrlMatcher — it will be the best choice.

What is mezon/router?

mezon/router now is:

  • php 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 )

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

No responses yet

Write a response