Measuring Performance using Timer

If you ever need to do light-weight profiling of your QCubed application, you might find the Timer class useful. It's really simple: you can start a named timer by doing Timer::start('timerName'); you can stop it; you can restart the timer later if you want to. When you're done measuring a section of your code, just call Timer::getTime('timerName'). If you had several timers running, an easy way to dump all the interesting debug info is to call Timer::varDump().

Each of the timers is internall maintained as a Timer object. If you want to know more about the timers - for example, the number of times the timer was started - you can get the Timer object instance, and then interrogating that instance:

$objTimer = Timer::getTimer('timerName');
echo $objTimer->CountStarted;

Take a look at a sample usage example below by clicking View Source.

Here's how long it took to execute the long calculation: 0.0067729949951172

Results of Timer::varDump():
longCalculation - start count: 2 - execution time: 0.013351
loadPersons - start count: 1 - execution time: 0.002777