loading...
Cover image for New PHP router wich is 24 to 42 times fatser then Yii2 router

New PHP router wich is 24 to 42 times fatser then Yii2 router

alexdodonov profile image alexdodonov Updated on ・2 min read

php routes benchmarks (10 Part Series)

1) New php router is 25 times faster then klein router 2) New PHP router wich is 7 to 15 times faster then Symfony router 3 ... 8 3) New PHP router wich is 30 to 50 times faster then Laravel router 4) New PHP router wich is 24 to 42 times fatser then Yii2 router 5) Real life comparison of Symfony router and Mezon router 6) Real life comparison of Symfony router and Mezon router. Part 2 7) Benchmark of PHP Altorouter 8) New benchmark shows that Mezon PHP Router is up to 60 times faster then Slim one 9) Benchmark of Mezon PHP Router and LeagueRouter 10) Mezon PHP Router is up to 82 times fatser then Bramus Router

Intro

Hello people! This article is a new one in a series of my benchmarking experiments. And today we shall find out what's the difference in performance of Yii2 router and mezon/router.

Like in the previous articles we shall test static routes and routes with parameters in them.

But before it we have to define the most primitive controller:

<?php
namespace console\controllers;

use yii\web\Controller;

// minimum possible functionality
class BenchmarkController extends Controller
{

    public function actionStatic(): string
    {
        return 'static';
    }

    public function actionParam(): string
    {
        return 'param';
    }
}

Then we need to configure route with parameter:

// somewere in main.php
'components' => [
    // other staff here

    // and our setup
    'urlManager' => [
        'enablePrettyUrl' => true,
        'showScriptName' => false,
        'rules' => [
            // our route with parameter
            'benchmark/<id:\d>' => 'benchmark/param'
        ],
    ]
]

Static routes will be benchmarked in this way:

<?php
// it's is normal Yii mess, don't panic )))
defined('YII_DEBUG') or define('YII_DEBUG', false);
defined('YII_ENV') or define('YII_ENV', 'production');

require __DIR__ . '/../vendor/autoload.php';
require __DIR__ . '/../vendor/yiisoft/yii2/Yii.php';
require __DIR__ . '/../common/config/bootstrap.php';
require __DIR__ . '/config/bootstrap.php';

$config = yii\helpers\ArrayHelper::merge(require __DIR__ . '/../common/config/main.php', require __DIR__ . '/../common/config/main-local.php', require __DIR__ . '/config/main.php', require __DIR__ . '/config/main-local.php');

$app = new yii\web\Application($config);

// here we try to launch our console script as it was called in web
$_SERVER['REQUEST_URI'] = '/yii2/yii2-app-advanced/console/test.php/benchmark/static';
$_SERVER['REQUEST_METHOD'] = 'GET';
$_SERVER['PHP_SELF'] = '/benchmark/static';
$_SERVER['SCRIPT_NAME'] = '/yii2/yii2-app-advanced/console/test.php';

// and here our benchmark itself
$iterationsCount = 10000;
$start = microtime(true);
for ($i = 0; $i < $iterationsCount; $i ++) {
    $request = new yii\web\Request();
    $app->handleRequest($request);
}
print($iterationsCount / (microtime(true) - $start));

And routes with parameters will be benchmarked like this:

// some variations from the previous benchmark
$_SERVER['REQUEST_URI'] = '/yii2/yii2-app-advanced/console/test.php/benchmark/1';
$_SERVER['PHP_SELF'] = '/benchmark/1';

The loop in wich we run $app->handleRequest($request) will be the same.

In this table you can see amount of dispatched routes per second. So this means that the bigger number means better. And for an all purpose framework the result is not bad. But mezon/router is faster )))

table

graph

As you can see - mezon/touter is from 24 to 43 times faster than Yii2 router.

What is mezon/router?

mezon/router now is:

  • framework for routing with 100% code coverage
  • 10.0 points at scrutinizer-ci.com
  • router is a part of the Mezon Project

Repo on github.com: https://github.com/alexdodonov/mezon-router

I'll be very glad if you'll press "STAR" button )

php routes benchmarks (10 Part Series)

1) New php router is 25 times faster then klein router 2) New PHP router wich is 7 to 15 times faster then Symfony router 3 ... 8 3) New PHP router wich is 30 to 50 times faster then Laravel router 4) New PHP router wich is 24 to 42 times fatser then Yii2 router 5) Real life comparison of Symfony router and Mezon router 6) Real life comparison of Symfony router and Mezon router. Part 2 7) Benchmark of PHP Altorouter 8) New benchmark shows that Mezon PHP Router is up to 60 times faster then Slim one 9) Benchmark of Mezon PHP Router and LeagueRouter 10) Mezon PHP Router is up to 82 times fatser then Bramus Router

Posted on by:

Discussion

markdown guide
 

Hello,
Quite interesting numbers. Did you extracted the routing modules from the non-mezon frameworks also? Do you plan to put mezon into an actual fully functional framework and test against real-world usage also?
There will be more test, against like POP, CI, Lumen or Slim?

Do you plan to add real stress-test or ioncannon test to prove it is actually safer and really faster?

 

Did you extracted the routing modules from the non-mezon frameworks also?

Yes, you can see another benchmarks in my previous articles.

Do you plan to put mezon into an actual fully functional framework and test against real-world usage also?

I do.

There will be more test, against like POP, CI, Lumen or Slim?

Put it in my content plan

Do you plan to add real stress-test or ioncannon test to prove it is actually safer and really faster?

I do