Welcome Guest, Not a member yet? Register   Sign In
Benchmarking Ci4 router
#1

Benchmarking Ci 4  router vs Symfony router ..... 35 000 routes most of them static

 results  Ci 4
PHP Code:
Code:
Array
(
    [map_codeigniter] => Array
        (
            [duration] => 0.2808
            [memory] => 48.82 mb
        )

    [match_codeigniter] => Array
        (
            [duration] => 0.4066
            [memory] => 1.06 kb
        )
results Symfony


PHP Code:
Code:
[map_symfony] => Array
        (
          [duration] => 0.078
            [memory] => 26.17 mb
        )

    [symfony_match] => Array
        (
         [duration] => 0.0936
            [memory] => 15.94 mb
        ) 



PHP Code:
Code:
function random_request_url() {
    $characters = 'abcdefghijklmnopqrstuvwxyz';
    $charactersLength = strlen($characters);
    $randomString = '/';
    // create random path of 5-20 characters
    for ($i = 0; $i < rand(5, 20); $i++) {
        $randomString .= $characters[rand(0, $charactersLength - 1)];
        if( rand(1, 10) === 1 ) {
           $randomString .= '/';
        }
    }
    // add dynamic route with 10% chance
    if ( rand(1, 10) === 1 ) {
       $randomString = rtrim( $randomString, '/' ) . '/[:part]';
    }
    return $randomString;
}

// generate a random request method
function random_request_method() {
    static $methods = array( 'GET', 'GET', 'POST', 'PUT', 'PATCH', 'DELETE' );
    $random_key = array_rand( $methods );
    return $methods[ $random_key ];



PHP Code:
Code:
$routes = $this->getCollector();
$this->request = Services::request();
    $nRoutes = 35000;
         $requests = array();
         for($i=0; $i<$nRoutes; $i++) {
         $requests[] = array(
        'method' => \random_request_method(),
        'url' => \random_request_url(), 
        'target' => 'App\Controllers\Test::display',
        'name'=>'route_name'.$i
         );
         }    
        $requests[] = array(
        'method' => \random_request_method(),
        'url' => 'blog/hhh', 
        'target' => 'App\Controllers\Test::show',
        'name'=>'routename_bb'
       );
    
    
\Bench::start('map_codeigniter');
   foreach($requests as $r) {
     $routes->add($r['url'], $r['target']);
  }
\Bench::stop('map_codeigniter');
\Bench::start('match_codeigniter');
$router = new Router($routes, $this->request);
        $router->handle('blog/hhh');
        
\Bench::stop('match_codeigniter'); 
PHP Code:
Code:
$nRoutes = 35000;
$requests = array();
for($i=0; $i<$nRoutes; $i++) {
    $requests[] = array(
        'method' => random_request_method(),
        'url' => random_request_url(),
    );
}
echo count($requests);
    Bench::start('symfony');
    $routes = new RouteCollection();
    Bench::start('map_symfony');
 
    foreach($requests as $i=> $r) {
        $route = new Route( $r['url'], array('controller' => 'MyController'));
        $routes->add('handler' . $i, $route);
       
    }
Bench::stop('map_symfony');
$r = $requests[array_rand($requests)];

Bench::start('symfony_match');
    $context = new RequestContext($r['url']);
    $matcher = new UrlMatcher($routes, $context);
     try {
    $parameters = $matcher->match($r['url']);
     } catch (Exception $e) {
        }
        
Bench::stop('symfony_match'); 
Reply


Messages In This Thread
Benchmarking Ci4 router - by tony.a - 09-11-2019, 03:22 PM
RE: Benchmarking Ci4 router - by tony.a - 09-12-2019, 01:36 AM
RE: Benchmarking Ci4 router - by kilishan - 09-12-2019, 06:28 AM
RE: Benchmarking Ci4 router - by albertleao - 09-12-2019, 08:21 AM
RE: Benchmarking Ci4 router - by tony.a - 09-12-2019, 10:07 AM
RE: Benchmarking Ci4 router - by kilishan - 09-12-2019, 10:17 AM
RE: Benchmarking Ci4 router - by tony.a - 09-12-2019, 10:22 AM
RE: Benchmarking Ci4 router - by kilishan - 09-12-2019, 10:29 AM
RE: Benchmarking Ci4 router - by tony.a - 09-12-2019, 12:02 PM
RE: Benchmarking Ci4 router - by kilishan - 09-12-2019, 12:47 PM
RE: Benchmarking Ci4 router - by tony.a - 09-12-2019, 11:47 PM
RE: Benchmarking Ci4 router - by tony.a - 09-13-2019, 01:39 AM
RE: Benchmarking Ci4 router - by chris.m - 08-06-2020, 05:53 PM



Theme © iAndrew 2016 - Forum software by © MyBB