Search

CodeIgniter Benchmarking

Benchmarking class is used to calculate the time between two points in your application. This class is initialized automatically by the system so there is no need to do it manually. In addition the benchmark is always started the moment the framework is invoked, and ended by the output class right before sending the final view to the browser, enabling a very accurate timing of the entire system execution to be shown.

Using the Benchmark Class

The Benchmark class can be used within your controllers, views, or your models. The process for usage is this:

  • Mark a start point
  • Mark an end point
  • Run the “elapsed time” function to view the results

Example using real code :

<?php
  $this->benchmark->mark('code_start');
  // Some code happens here
  $this->benchmark->mark('code_end');
  echo $this->benchmark->elapsed_time('code_start', 'code_end');
?>

Displaying Memory Consumption

To display the memory usage, use the function memory_usage() as shown in the following code.

<?php echo $this->benchmark->memory_usage(); ?>

Displaying Total Execution Time

To display the total time usage for loading page, use the function elapsed_time() as shown in the following code.

<?php echo $this->benchmark->elapsed_time();?>

Stack Overlode is optimized Tutorials and examples for learning and training. Examples might be simplified to improve reading and learning and understand. Tutorials and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using Stack Overlode, you agree to have read and accepted our terms of use, cookie and privacy policy.