Support the ongoing development of Laravel.io →
Database Eloquent Architecture
Last updated 2 years ago.
0

Check out this paste bin http://laravel.io/bin/881Xx

Last updated 2 years ago.
0

That's fantastic, sir, and quite helpful. For those not in IRC, egekhter has done some benchmarking that shows Eloquent to be two orders of magnitude (and change) slower on queries like this than just running a raw SQL query. I'm going to experiment a bit and see what I can come up with. I'll report back.

Last updated 2 years ago.
0

Most welcome. I'd like to add that there are 5 comparisons: Eloquent vs. Query Builder vs. QueryBuilder optimized, vs. Raw PHP->MySql vs. Raw MySql

Here are the times for each for an arbitrary select statement:

Eloquent = 6400 ms Query Builder = 3700 ms Query Builder optimized = 623 ms Raw PHP->MySql = 162 ms Raw Sql = 35 ms

The optimized method is:

//getOpt() method in Query/Builder.php
public function getOpt()
    {
        
        // ~ 36% to compile select statement without bindings
        $sql = $this->grammar->compileSelect($this);
        
        // < 1% to get bindings        
        $bindings = $this->getBindings($this);
        
        // 38% to compile select statement with bindings
        foreach ($bindings as $b)
        {
            $sql = preg_replace('/\?/', $b, $sql, 1);
        }
 
        // ~ 25% to execute and return the actual results
        return $this->connection->select($sql);
 
    }

If not for the compiling of the select statement and setting the dynamic bindings, this complex query would return in only 162ms.

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

mossface mossface Joined 28 Jul 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.