CodeIgniter Active Record vs. Explicit
When dealing with frameworks, such as Code Igniter, there is always a question of what type of overhead it adds to application. One rainy day not too long ago we ran some really simple tests on the difference between active record queries, and explicit queries in CI, and decided it might be nice to share the results. There is always the question of “is it faster”, and while our results show explicit SQL queries to be faster, database execution time is almost always negligible when compared to PHP run time, or page load speeds.
The Setup
We wanted to keep this test pretty bare-bones, so we could really nail down the overhead of just the active record processing. We loaded up a fresh copy of Code Igniter version 1.7.3, and created a typical controller-model relationship. Next, we created a simple timer using PHP’s microtime() function, and wrapped our calls in a for-loop, so it would repeat 1000 times. On each loop it logged the time difference of just the query itself, and at the end it exported to a .csv file so we could chart it up.
GET Query Times
Average Times (s) Explicit Query: 0.000168 Active Record Query: 0.000309
INSERT Query Times
Average Times (s) Explicit Query: 0.000161 Active Record Query: 0.000259
UPDATE Query Times
Average Times (s) Explicit Query: 0.000172 Active Record Query: 0.000321
DELETE Query Times
Average Times (s) Explicit Query: 0.000172 Active Record Query: 0.000321
Conclusions
As you might see, and as you might expect, there is a “significant” overhead using CI’s active record; however, I put that in quotations because the time scale we are looking at is so darn small. When you are building applications that require 10e-5 precision on your database queries, well, you probably aren’t a general-purpose, curious developer.
Recent Comments
Archives
- April 2023
- January 2023
- November 2022
- May 2022
- March 2022
- January 2022
- December 2021
- April 2021
- December 2020
- October 2020
- August 2020
- July 2020
- March 2020
- February 2020
- January 2020
- December 2019
- November 2019
- October 2019
- January 2019
- December 2018
- November 2018
- August 2018
- July 2018
- April 2018
- March 2018
- November 2017
- October 2017
- February 2017
- October 2016
- August 2016
- July 2016
- November 2015
- October 2013
- February 2013
- January 2013
- August 2012
- July 2012
- June 2012
- May 2012
- April 2012
- February 2012
- December 2011