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

(This post was last modified: 09-12-2019, 12:16 PM by tony.a.)

At 40 mb and 1 sec  is not an option for sure .
trying not to hit the database to find the first segment and query various tables.
Is a Region ?
Is a city ?
Is a category ?
Is a subcategory ?
Is a page ?
Is a user ?
Altorouter (optimized )  vs Symfony benchmark same 8000 routes  (Spain has 8000 cities ).
Symfony 1 loop  random route match . 1 loop no match
[map_symfony] => Array
        (
            [start] => 1568314486.7859
            [end] => 1568314486.8639
            [start_memory] => 21650600
            [end_memory] => 49116216
            [duration] => 0.07800007
            [memory] => 26.19 mb
        )

    [symfony_match] => Array
        (
            [start] => 1568314486.8639
            [end] => 1568314486.8951
            [start_memory] => 49116592
            [end_memory] => 54674560
            [duration] => 0.03119993
            [memory] => 5.3 mb
        )

    [symfony_no_match] => Array
        (
            [start] => 1568314486.8951
            [end] => 1568314487.1291
            [start_memory] => 54674936
            [end_memory] => 97618904
            [duration] => 0.23399997
            [memory] => 40.95 mb
        )
Altorouter 10000  loops to match 10 000 loops no match 

[map_altorouter] => Array
        (
            [start] => 1568315731.476
            [end] => 1568315731.476
            [start_memory] => 8039096
            [end_memory] => 11265408
            [duration] => 0
            [memory] => 3.08 mb
        )

    [altorouter_match] => Array
        (
            [start] => 1568315731.476
            [end] => 1568315731.5228
            [start_memory] => 11265784
            [end_memory] => 11265784
            [duration] => 0.04680014
            [memory] => NAN b
        )

    [altorouter_no_match] => Array
        (
            [start] => 1568315731.5228
            [end] => 1568315731.5696
            [start_memory] => 11266160
            [end_memory] => 11266160
            [duration] => 0.0467999
            [memory] => NAN b
        )




PHP Code:
$nRoutes 8000;
$requests = array();
for(
$i=0$i<$nRoutes$i++) {
    $requests[] = array(
        'method' => random_request_method(),
        'url' => random_request_url(), 
'target' => 'Home::index',
'name'=>'scriptswatre'.$i
    
);

//echo count($requests);

$router = new AltoRouter();
// map requests
Bench::start('map_altorouter');



foreach(
$requests as $r) {
    $router->map($r['method'], $r['url'], $r['target'],$r['name']);
}
Bench::stop('map_altorouter');

// pick random route to match
$r $requests[array_rand($requests)];
p_print_r($r);
Bench::start('altorouter_match');
for(
$i=0$i<10000$i++) {
  $match $router->match($r['url'], $r['method']);


//p_print_r($match);
Bench::stop('altorouter_match');

Bench::start('altorouter_no_match');
for(
$i=0$i<10000$i++) {
$router->match('/55-foo-bar''GET');
}
Bench::stop('altorouter_no_match');



at extra 3 mb and this speed to match  is a viable option to replace the database lookup
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