IntroductionSpeediness (execution) is one of the
principles for RawDev. In order to both improve the execution time of
your code as well as getting a better feel for how your coding impacts
performance the RTimer object is a useful tool. The RTimer object is
very simple and useful for simple situations. Examples of more advanced
tools are xdebug profiler data and apache "ab" which tests performance
under load.
How it worksThe RTimer
tool works just like a stopwatch. You can start the timer and take lap
times. Lap times can be associated with labels. You can display an
overview of all lap times and the total time. All methods are static so
that time measurements can be taken anywhere without the use of global
variables.
Example<?php
require_once("rawdev/RawDev.php"); require_once(RAWDEV_LIB.'/Util/Timer.php');
RTimer::start(); # starts the timer
usleep(123);
RTimer::lap('sleep'); # records a lap time with label 'sleep'
RTimer::display(); # displays the lap times
?>
Resultsphp ~/rawdev/samples/Util/timer.php sleep: 0.000248sec Total: 0.000248sec
ConclusionI personally use this
library all the time. It helps me become a better programmer by
understanding which statements take longer then others. The timer is
extremely easy to use but does not take performance testing under heavy
load into account. Other tools such as the xdebug profiler are useful
as well but they take more time to setup. Finally,
executing timer functions take time themselves (< ~.0001sec) so
you want to (a) just be aware of that, (b) execute a piece of code
multiple times (e.g. 100 times) to get a more accurate picture.
Links |