From 8ede1a2ecbb62577afd32996956c5feaf7ddf9b6 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Wed, 5 Oct 2011 13:34:52 -0500 Subject: replacing the old HTML user guide with a Sphinx-managed user guide --- user_guide_src/source/libraries/benchmark.rst | 122 ++++++++++++++++++++++++++ 1 file changed, 122 insertions(+) create mode 100644 user_guide_src/source/libraries/benchmark.rst (limited to 'user_guide_src/source/libraries/benchmark.rst') diff --git a/user_guide_src/source/libraries/benchmark.rst b/user_guide_src/source/libraries/benchmark.rst new file mode 100644 index 000000000..2588f72a2 --- /dev/null +++ b/user_guide_src/source/libraries/benchmark.rst @@ -0,0 +1,122 @@ +################## +Benchmarking Class +################## + +CodeIgniter has a Benchmarking class that is always active, enabling the +time difference between any two marked points to be calculated. + +.. note:: 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. + +.. contents:: Table of Contents + +Using the Benchmark Class +========================= + +The Benchmark class can be used within your +:doc:`controllers `, +:doc:`views `, or your :doc:`models `. +The process for usage is this: + +#. Mark a start point +#. Mark an end point +#. Run the "elapsed time" function to view the results + +Here's an example using real code:: + + $this->benchmark->mark('code_start'); + + // Some code happens here + + $this->benchmark->mark('code_end'); + + echo $this->benchmark->elapsed_time('code_start', 'code_end'); + +.. note:: The words "code_start" and "code_end" are arbitrary. They + are simply words used to set two markers. You can use any words you + want, and you can set multiple sets of markers. Consider this example:: + + $this->benchmark->mark('dog'); + + // Some code happens here + + $this->benchmark->mark('cat'); + + // More code happens here + + $this->benchmark->mark('bird'); + + echo $this->benchmark->elapsed_time('dog', 'cat'); + echo $this->benchmark->elapsed_time('cat', 'bird'); + echo $this->benchmark->elapsed_time('dog', 'bird'); + + +Profiling Your Benchmark Points +=============================== + +If you want your benchmark data to be available to the +:doc:`Profiler ` all of your marked points must +be set up in pairs, and each mark point name must end with _start and +_end. Each pair of points must otherwise be named identically. Example:: + + $this->benchmark->mark('my_mark_start'); + + // Some code happens here... + + $this->benchmark->mark('my_mark_end'); + + $this->benchmark->mark('another_mark_start'); + + // Some more code happens here... + + $this->benchmark->mark('another_mark_end'); + +Please read the :doc:`Profiler page ` for more +information. + +Displaying Total Execution Time +=============================== + +If you would like to display the total elapsed time from the moment +CodeIgniter starts to the moment the final output is sent to the +browser, simply place this in one of your view templates:: + + benchmark->elapsed_time();?> + +You'll notice that it's the same function used in the examples above to +calculate the time between two point, except you are **not** using any +parameters. When the parameters are absent, CodeIgniter does not stop +the benchmark until right before the final output is sent to the +browser. It doesn't matter where you use the function call, the timer +will continue to run until the very end. + +An alternate way to show your elapsed time in your view files is to use +this pseudo-variable, if you prefer not to use the pure PHP:: + + {elapsed_time} + +.. note:: If you want to benchmark anything within your controller + functions you must set your own start/end points. + +Displaying Memory Consumption +============================= + +If your PHP installation is configured with --enable-memory-limit, you +can display the amount of memory consumed by the entire system using the +following code in one of your view file:: + + benchmark->memory_usage();?> + +.. note:: This function can only be used in your view files. The consumption + will reflect the total memory used by the entire app. + +An alternate way to show your memory usage in your view files is to use +this pseudo-variable, if you prefer not to use the pure PHP:: + + {memory_usage} + -- cgit v1.2.3-24-g4f1b From 70ff9c9b90e01fee332dc2b3c9376af2915494a7 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Wed, 5 Oct 2011 16:20:38 -0500 Subject: fixed code block spacing in Benchmark lib docs --- user_guide_src/source/libraries/benchmark.rst | 30 +++++++++++++-------------- 1 file changed, 15 insertions(+), 15 deletions(-) (limited to 'user_guide_src/source/libraries/benchmark.rst') diff --git a/user_guide_src/source/libraries/benchmark.rst b/user_guide_src/source/libraries/benchmark.rst index 2588f72a2..5b86142dd 100644 --- a/user_guide_src/source/libraries/benchmark.rst +++ b/user_guide_src/source/libraries/benchmark.rst @@ -30,11 +30,11 @@ The process for usage is this: Here's an example using real code:: $this->benchmark->mark('code_start'); - + // Some code happens here - + $this->benchmark->mark('code_end'); - + echo $this->benchmark->elapsed_time('code_start', 'code_end'); .. note:: The words "code_start" and "code_end" are arbitrary. They @@ -42,15 +42,15 @@ Here's an example using real code:: want, and you can set multiple sets of markers. Consider this example:: $this->benchmark->mark('dog'); - + // Some code happens here - + $this->benchmark->mark('cat'); - + // More code happens here - + $this->benchmark->mark('bird'); - + echo $this->benchmark->elapsed_time('dog', 'cat'); echo $this->benchmark->elapsed_time('cat', 'bird'); echo $this->benchmark->elapsed_time('dog', 'bird'); @@ -64,16 +64,16 @@ If you want your benchmark data to be available to the be set up in pairs, and each mark point name must end with _start and _end. Each pair of points must otherwise be named identically. Example:: - $this->benchmark->mark('my_mark_start'); - + $this->benchmark->mark('my_mark_start'); + // Some code happens here... - - $this->benchmark->mark('my_mark_end'); - + + $this->benchmark->mark('my_mark_end'); + $this->benchmark->mark('another_mark_start'); - + // Some more code happens here... - + $this->benchmark->mark('another_mark_end'); Please read the :doc:`Profiler page ` for more -- cgit v1.2.3-24-g4f1b