File: Fogg/Util/Timer/Example.php

Recommend this page to a friend!
  Classes of Jacob Fogg  >  Central Timer  >  Fogg/Util/Timer/Example.php  >  Download  
File: Fogg/Util/Timer/Example.php
Role: Example script
Content type: text/plain
Description: Example file
Class: Central Timer
Measure the time elapsed between code sections
Author: By
Last change:
Date: 6 years ago
Size: 1,338 bytes
 

Contents

Download
<?php
require('Timer.php');

use
Fogg\Util\Timer\Timer;

//Instantiate a timer object directly
echo "Start the direct timer.<br>\n";
$directTimer = new Timer();

//Instantiate a timer object via the static method
echo "Start the 'central' timer.<br>\n";
$centralTimer = Timer::get_instance('central');

//Pause the script for 2 seconds
echo "Pause for 2 seconds.<br>\n";
sleep(2);

//get the direct timer duration
echo "Direct timer duration (2 seconds): {$directTimer->elapsed()}<br>\n";

//reset the direct timer
echo "Resetting the direct timer.<br>\n";
$directTimer->reset();

//Instantiate a second timer object via the static method
//Not going to store the timer, because we can access it later through the same static method
echo "Start the 'secondTimer', but don't store the instance.<br>\n";
Timer::get_instance('secondTimer');

//Pause the script for 2 more seconds
echo "Pause for 2 more seconds.<br>\n";
sleep(2);

//display the durations of the three timers
echo "Direct timer duration (2 seconds): {$directTimer->elapsed()}<br>\n";
echo
"'central' timer duration (4 seconds): {$centralTimer->elapsed()}<br>\n";
echo
"Fetch the 'secondTimer' instance.<br>\n";
$secondTimer = Timer::get_instance('secondTimer');
echo
"'secondTimer' duration (2 seconds): {$secondTimer->elapsed()}<br>\n";


For more information send a message to info at phpclasses dot org.