CodeIgniter - Benchmarking

CodeIgniter - Benchmarking

CodeIgniter - Benchmarking

Setting breakpoints

If you want to measure the time it takes to execute a set of lines or memory usage, you can calculate it using breakpoints in CodeIgniter. To do this, CodeIgniter has a separate class " Benchmarking ".

This class is loaded automatically; You don't have to download it. It can be used anywhere in your controller, view and model classes. All you have to do is mark the start and end points and then execute the elapsed_time() function between those two marked points and you can get the time it takes to execute this code as shown below.

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


Create a controller named Profiler_controller.php and save it to application/controller/Profiler_controller.php


Create a view file named test.php and save it to application/views/test.php








      CodeIgniter View Example



Edit the route.php file in application/config/rout.php to add the route for the above controller and add the following line at the end of the file.

$route['profiler'] = "Profiler_controller";

$route['profiler/disable'] = "Profiler_controller/disable"

After that, you can enter the following URL into your browser's address bar to run the example.

The above URL will activate the profiler and it will output data as shown in the following screenshot.

To disable profiling, run the following URL.