From b0dd10f8171945e0c1f3527dd1e9d18b043e01a7 Mon Sep 17 00:00:00 2001 From: admin Date: Fri, 25 Aug 2006 17:25:49 +0000 Subject: Initial Import --- user_guide/libraries/benchmark.html | 160 ++++++++++++++++++++++++++++++++++++ 1 file changed, 160 insertions(+) create mode 100644 user_guide/libraries/benchmark.html (limited to 'user_guide/libraries/benchmark.html') diff --git a/user_guide/libraries/benchmark.html b/user_guide/libraries/benchmark.html new file mode 100644 index 000000000..1f72f3531 --- /dev/null +++ b/user_guide/libraries/benchmark.html @@ -0,0 +1,160 @@ + + + + +Code Igniter User Guide + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +

Code Igniter User Guide Version 1.4.0

+
+ + + + + + + + + +
+ + +
+ + + +
+ + +

Benchmarking Class

+ +

Code Igniter 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.

+ +

Using the Benchmark

+ +

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

    +
  1. Mark a start point
  2. +
  3. Mark an end point
  4. +
  5. Run the "elapsed time" function to view the results
  6. +
+ +

Here's an example using real code:

+ +$this->benchmark->mark('start');
+
+// Some code happens here
+
+$this->benchmark->mark('end');
+
+echo $this->benchmark->elapsed_time('start', 'end');
+ +

Note: The words "start" and "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');
+ + +

Displaying Total Execution Time

+ +

If you would like to display the total elapsed time from the moment Code Igniter starts to the moment the final output +is sent to the browser, simply place this in one of your view templates:

+ +<?=$this->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, Code Igniter 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:

+ +<?=$this->benchmark->memory_usage();?> +

Note: This function can only be used in your view files. The consumpiton 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} + + + +
+ + + + + + + \ No newline at end of file -- cgit v1.2.3-24-g4f1b