Welcome Guest, Not a member yet? Register   Sign In
Active record class VS simple query
#1

[eluser]saidai jagan[/eluser]
Hai,
Any body tell which is fast.
Using active record class
$this->db->get('my table');
OR
Using query method ,
$this->db->query('select * from table');
#2

[eluser]n0xie[/eluser]
Obviously doing a query directly is faster since the Active Record class first has to 'build' the query.
#3

[eluser]saidai jagan[/eluser]
Yeah thanx man. That was i wanted. Smile
#4

[eluser]Zeeshan Rasool[/eluser]
informative !
#5

[eluser]BrianDHall[/eluser]
$this->db->get('my_table') is faster, because it is less typing and its hard to screw up the syntax.

There is of course a big difference in execution time/resources and development speed Smile

Always the word of caution, but it is likely the difference in speed is on the order of fractions of a millisecond - avoid using query strings directly just because they are 'faster', for the same reason you use CI even though just using a pure php spaghetti-coded page would be 'faster'.

Put if you have profiled your application and determined that AR functions are a significant constraining factor to application performance and a pseudo-test has been done to confirm you aren't wasting your time, then you should in fact drop built-in database objects entirely where possible and rely on direct system-specific optimized query calls - it might buy you more than a handful of clockcycles that ->query() vs ->get() could ever buy you. Still seems like a bit of a local optimization, but YMMV.
#6

[eluser]saidai jagan[/eluser]
OH. FYI i checked both (get() and query()) methods in the output profiler system.It shows get() is much better than query() :-S .Any information ???
#7

[eluser]BrianDHall[/eluser]
[quote author="saidai jagan" date="1257259099"]OH. FYI i checked both (get() and query()) methods in the output profiler system.It shows get() is much better than query() :-S .Any information ???[/quote]

I ran some tests on my live server and tested three things:

1- ORM approach (create an object and use get).
2- db->query()
3- db->get()

I found get to be the fastest, query to be .002-.005 seconds slower, and the orm method to be .007 slower.

So the difference in the slowest and the fastest require about 35 queries to cause even a quarter of a second of difference in performance.

Seems kind of a minor difference, but dunno why get() actually runs ever so slightly faster.

For fun I tested $i++ vs ++$i, just cause, and it takes 100,000 uses to score .005 seconds of difference in performance. For those keeping track, that is 5,000,000 increments to be a quarter of a second of difference Smile
#8

[eluser]saidai jagan[/eluser]
Yeah i also tested in the live server.
The query() method running at 0.0465 secs.
but the get() runs at 0.0355 secs.
But i thought query() is faster now i get to kno get() is much much better for me.
Is this a valid point?
#9

[eluser]BrianDHall[/eluser]
[quote author="saidai jagan" date="1257415933"]Yeah i also tested in the live server.
The query() method running at 0.0465 secs.
but the get() runs at 0.0355 secs.
But i thought query() is faster now i get to kno get() is much much better for me.
Is this a valid point?[/quote]

Well, that's 0.011 seconds difference - if you run the query 10 times that is 1/10th of 1 second. Are you running an application where such a load actually matters, or is most of your servers capacity unused anyway? Is lag time running queries noticably slowing your applications response time?

If it is a constraint of the system, it matters - otherwise, it doesn't.

The principle of avoiding premature optimization is to code for maximum development speed, then only when performance becomes an issue do you go back and seek to optimize only if it makes any sense.
#10

[eluser]saidai jagan[/eluser]
Thanks fa u r reply !! Smile.
so shall i use query() rather than get()?.




Theme © iAndrew 2016 - Forum software by © MyBB