Eliminating Benchmarking and Hooks in CodeIgniter for Speed Improvement

Out of curiosity, I did a few tests on PHP 5.2.5 locally to see if the already zippy CodeIgniter could be sped up or made more efficient by removing Extension Hooks and the Benchmarking class, which occasionally get criticized for always being loaded and called even when the user is never taking advantage of the two classes.  Hold on to your hats…

My controller is simple:

  1. $this->output->enable_profiler(TRUE);
  2. echo 'Hi there!';

And the results:

  1. /*
  2. NORMAL
  3. Total Execution Time 0.0172
  4. 689,672 bytes memory
  5. NO HOOKS
  6. Total Execution Time 0.0153
  7. 666,536 bytes memory
  8. NO BENCHMARKING
  9. Total Execution Time 0.0179
  10. 685,360 bytes memory
  11. */

Now of course, the Heisenberg uncertainty principle is at play here, particularly with the last test.  How can you test the speed gain of the removal of code that measures how long the application takes to run?  I removed the class call, and replaced the markers where it measures the start and stop of application processing with microtime() and did some subtraction.  Not a whole lot less than what the Benchmark class does itself, but it is removing the class and overhead of the calls to it, hence the fractional drop in memory consumption.

Your results may, nay, will vary, and these things are always impossible to make firm statements about, but I think it sufficiently demonstrates that if you are worried about either of these two classes making your application inefficient, that you’d do better to look at and worry about your own application code, and having a quality host, both of which will certainly have a measurable impact on your site’s performance.