08.10.2017 Views

codeigniter_tutorial

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

21. Benchmarking<br />

CodeIgniter<br />

Setting Benchmark Points<br />

If you want to measure the time taken to execute a set of lines or memory usage, you<br />

can calculate it by using Benchmarking points in CodeIgniter. There is a separate<br />

“Benchmarking” class for this purpose in CodeIgniter.<br />

This class is loaded automatically; you do not have to load it. It can be used anywhere in<br />

your controller, view, and model classes. All you have to do is to mark a start point and<br />

end point and then execute the elapsed_time() function between these two marked<br />

points and you can get the time it took to execute that code as shown below.<br />

<br />

To display the memory usage, use the function memory_usage() as shown in the<br />

following code.<br />

<br />

echo $this->benchmark->memory_usage();<br />

Example<br />

Create a controller called Profiler_controller.php and save it in<br />

application/controller/Profiler_controller.php<br />

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!