DEV Community

Discussion on: Cake\Collection\Collection vs Illuminate\Support\Collection

Collapse
 
maddrid profile image
maddrid • Edited

Hey ! Did some tests , here is the results :
Filter 50 categories

Bench::start('get_categories_cake');
$buff = new \Cake\Collection\Collection($all);

for ($i = 0; $i < 10000; $i++) {

    $ladies = $buff->filter(function ($category, $key) {

        return $category['pk_i_id'] === '22';
    });
    $get_cake = $ladies->toArray();
}
Bench::stop('get_categories_cake');
d($get_cake);


Bench::start('get_categories_laravel');
$collection = new Illuminate\Support\Collection($all);
for ($i = 0; $i < 10000; $i++) {
    $filtered = $collection->filter(function ($value, $key) {
        return $value['pk_i_id'] === '22';
    });

    $get_laravel = $filtered->all();
}
Bench::stop('get_categories_laravel');
d($get_laravel);
Enter fullscreen mode Exit fullscreen mode

Results :

 [get_categories_cake] => Array
        (
            [cpu_load] => Not enabled
            [duration] => 0.17000103
            [memory] => 267.4 kb
            [peak] => 6.46 mb
        )

    [get_categories_laravel] => Array
        (
            [cpu_load] => Not enabled
            [duration] => 0.05999994
            [memory] => 395.09 kb
            [peak] => 6.46 mb
        )
Enter fullscreen mode Exit fullscreen mode