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();?>