Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

How Phalcon is faster than PDO?

Hi

i'm new to phalcon and i really like it. I just did a simple compare beetwen phql and pdo. I have a simple table named user with 4 columns and 10K rows.

using pdo

$t = microtime(true);
$db = new PDO('mysql:host=localhost;dbname=phalcon;charset=utf8', 'root', 'dbpass');
$stm = $db->query("SELECT * FROM user");
$rows = $stm->fetchAll(PDO::FETCH_ASSOC);
echo microtime(true) - $t;
echo '<br/>';
echo memory_get_usage(true);

and result

    0.083003997802734
    7602176

using phalcon

$t = microtime(true);
$builder = $this->modelsManager->createBuilder();
$users = $builder->from('user')->->getQuery()->execute();
echo microtime(true) - $t;
echo '<br/>';
echo memory_get_usage(true);

and result

    0.069004058837891
    2097152

Amazingly both proccess time and memory usage in phalcon is lower than pdo. As I know phalcon use pdo at the backend and returns model classes instead of pure array. How come that is possible?

edited Sep '15

As far as I remember phql doesn't use pdo in backend, they use something similar to mysqli, for performance reasons. This would explain why phql is faster than pure pdo (correct me if i'm wrong)



67.7k

after you run 1 of the benchmarks restart the mysql server, then run the second.

and tell us if it is still the same :-)

As far as I remember phql doesn't use pdo in backend, they use something similar to mysqli, for performance reasons. This would explain why phql is faster than pure pdo (correct me if i'm wrong)

I don't think that's correct. I've seen multiple replies here where @Phalcon says PHQL doesn't support this thing or that thing because PDO doesn't support it.

As far as I remember phql doesn't use pdo in backend, they use something similar to mysqli, for performance reasons. This would explain why phql is faster than pure pdo (correct me if i'm wrong)

In order to use phql you need to enable php pdo mysql (for mysql) extension.

after you run 1 of the benchmarks restart the mysql server, then run the second. and tell us if it is still the same :-)

I had disabled query cache when i ran benchmarks. I restart mysql before running each benchmark for sure and still same result. The intersting part for me is memory usage. phql returns heavy models classes vs pdo that returns pure arrays but memory usage is about 25%.

I like it.



16.1k
Accepted
answer

cf https://github.com/phalcon/cphalcon/blob/master/phalcon/mvc/model/resultset.zep#L143-L156

fetch is done only if resulset as less than 32 results

so here you test is quite logical : you compare different things : one will get 10k results, the other will only execute the requests.

Thank you for you answer.