revIgniter has a Benchmarking library that is always active, enabling the time difference between any two marked points to be calculated.
Note: This library 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 library right before sending the final view to the browser, enabling a very accurate timing of the entire system execution to be shown.
Table of Contents
Using the Benchmark Library
- Mark a start point
- Mark an end point
- Run the "elapsed time" function to view the results
Here's an example using real code:
rigTimeMark "codeStart" # Some code happens here rigTimeMark "codeEnd" put rigElapsedTime("codeStart", "codeEnd")
Note: The words "codeStart" and "codeEnd" 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:
rigTimeMark "dog" # Some code happens here rigTimeMark "cat" # More code happens here rigTimeMark "bird" put rigElapsedTime("dog", "cat") into tDogCat put rigElapsedTime("cat", "bird") into tCatBird put rigElapsedTime("dog", "bird") into tDogBird put tDogCat && tCatBird && tDogBird
Profiling Your Benchmark Points
If you want your benchmark data to be available to the 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:
rigTimeMark "myMark_start" # Some code happens here... rigTimeMark "myMark_end" rigTimeMark "anotherMark_start" # Some more code happens here... rigTimeMark "anotherMark_end"
Please read the Profiler page for more information.
Displaying Total Execution Time
If you would like to display the total elapsed time from the moment revIgniter starts to the moment the final output is sent to the browser, simply place this in one of your view templates:
<? return rigElapsedTime() ?>
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, revIgniter 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 notation with double braces:
Using this notation benchmarking works even with cached pages.
Note: If you want to benchmark anything within your controller handlers you must set your own start/end points.