We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

phalcon takes 38 seconds while laravel takes 2.5 seconds

i try to load 41000 records from databaase using laravel and phalcon 3 as a test

on phalcon i wrote

$provinces = Provinces::find();

foreach ($provinces as $province) {

echo $province->name;

=============================

on laravel i wrote

$provinces = Province::all();

foreach ($provinces as $province) {

echo $province->name ;

}

phalcon takes 38 seconds to finsih loading while laravel takes 3 seconds only !!

why this big diffrerence ?

edited Aug '16

Hmm I think it is something with your current configuration... Just did a test with salaries table with 2.9m records and 100mb of data.

$start = microtime(true);
$data = \Models\Salaries::find([
    'limit' => 50000
]);
foreach ($data as $item) {
    echo 'Salary: '. $item->salary . ' from '. $item->date_1 .' to '. $item->date_2 . '<br/>';
}
echo 'Time: ', microtime(true) - $start;
exit;

// Results with version 2.x
...
...
Salary: 78908 from 1995-09-14 to 1996-09-13
Salary: 83245 from 1996-09-13 to 1997-09-13

Time: 0.74881386756897

// Results with version 3.x
...
...
Time: 5.0550677776337

Sample data: https://launchpad.net/test-db/+download

Please note: I just installed version 3.x to do this test, I did not yet have time to dig into the changes and to update my codebase. Perhaps there is something that I'm missing yet, but still the results are far from ~40 seconds.

Also note: Doing my tests on a project which has other services and functionalities going on, it's not just a plain script file.

UPDATE: Same test, but using the QueryBuilder:

$data = $this->modelsManager->createBuilder()
    ->columns([
        'salary',
        'date_1',
        'date_2'
    ])
    ->from('Models\Salaries')
    ->limit(50000)
    ->getQuery()->execute();

// Results
...
Time: 0.45169997215271

Well still difference between 2.x and 3.x is huge.



2.2k
edited Aug '16

i do the same as you do above it tooks with me 26 seconds to load 4100 records

what configuration so you mean ? i just put dll and point to it and use it with the sample tutorial

https://github.com/phalcon/tutorial

nothing more . what i should check ?



2.2k
edited Aug '16

Well still difference between 2.x and 3.x is huge.

do you mean that i should you 2.x instead .. im new to phalcon my first day :) well i try version 2 the diffrence is in 2 seconds only !!



85.5k
edited Aug '16

https://github.com/kenjis/php-orm-benchmark

would be nice if someone can add phalcon 3 to the pull



145.0k
Accepted
answer

I checked it on employees table from above. Will all properties it's 3.2 seconds for 300000 records after adding all properties to model. Without it it was like 13 seconds.



2.2k
edited Aug '16

yes @Jurigag i do like what you said and it is super super fast but i dont know why?

do you have an answer for this very strange behaviour ?

thanks in advance.

You are using php 7 right ? Then there it's known bug as far as i know. Perhaps on php 5 too, beacause there is reflection used for this for checking property and it's slowing down the application.



2.2k
edited Aug '16

yes @Jurigag im using php 5 ..

but now in laravel it tooks 2 seconds in phalcon it tooks half second

is this the best phalcon can provide

edited Aug '16

Well you can speed it up further by using arrays and getting certain columns like:

$provinces = Provinces::find([
'columns'=>'name'
])->toArray();

foreach ($provinces as $province) {

echo $province['name'];

You should avoid using objects, as well all columns for displaying only. Im guessing similar things can be done in laravel. Keep in mind while selecting certain columns there are Phalcon\Model\Row is used instead of your full model, so events etc added to models will not work.



2.2k

i know this @Jurigag

but im comparing to laravel in this case

Then im guessing not, but 4 times including db queries is already pretty huge.



2.2k

thanks alot @Jurigag

im sorry one last question regarding performance

now if i want to use any package ex. a package for export to excel

will it be faster when used in phacon compared to laravel

and as you know that all these packages are normal php not c extension like phalcon

No, it won't be faster, how it can be ? It will be still running in php. You got speed by using phalcon, some package for exporting to excel will work the same both on phalcon and laravel.