PHP Classes

Central Timer: Measure the time elapsed between code sections

Recommend this page to a friend!
  Info   View files Example   View files View files (2)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not yet rated by the usersTotal: 106 This week: 1All time: 9,676 This week: 560Up
Version License PHP version Categories
central-timer 1GNU General Publi...5.3PHP 5, Time and Date
Description 

Author

This class can measure the time elapsed between code sections.

It can record the current time and return the time that elapsed after a certain section code was executed.

The class can return multiple timer object instances to be able to measure the time that elapsed when running different code sections.

Picture of Jacob Fogg
  Performance   Level  
Name: Jacob Fogg <contact>
Classes: 7 packages by
Country: United States United States
Age: 44
All time rank: 1049149 in United States United States
Week rank: 411 Up48 in United States United States Up
Innovation award
Innovation award
Nominee: 3x

Winner: 1x

Example

<?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";


  Files folder image Files  
File Role Description
Files folder imageFogg (1 directory)

  Files folder image Files  /  Fogg  
File Role Description
Files folder imageUtil (1 directory)

  Files folder image Files  /  Fogg  /  Util  
File Role Description
Files folder imageTimer (2 files)

  Files folder image Files  /  Fogg  /  Util  /  Timer  
File Role Description
  Accessible without login Plain text file Example.php Example Example file
  Plain text file Timer.php Class Timer class file

 Version Control Unique User Downloads Download Rankings  
 0%
Total:106
This week:1
All time:9,676
This week:560Up