PHP Classes

File: TestStopWatch.php

Recommend this page to a friend!
  Classes of Bob Wedwick   PHP StopWatch Timer   TestStopWatch.php   Download  
File: TestStopWatch.php
Role: Example script
Content type: text/plain
Description: Example and test the Stop Watch
Class: PHP StopWatch Timer
Measure the time PHP scripts take to execute
Author: By
Last change:
Date: 9 years ago
Size: 1,303 bytes


Class file image Download
#!/usr/bin/php -q
# Use: php TestStopWatch.php
    # testing the stop watch class
include_once "StopWatchClass.php";

# create a stopwatch object
$watch = new stopwatch;

# restart the stop watch in milliseconds with a new name
$watch->Start('testing', false);

# sleep 1 second

# note the end of the interval
$watch->Interval('1 second later');

# sleep 2 seconds

# note the end of the interval
$watch->Interval("2 seconds later");

# loop doing nothing 100,000 times
for ($i = 0; $i <= 100000; ++$i) { ;}

# note the end of the loop
$watch->Interval("for-loop done");

# get the latest interval
echo "{$watch->GetNamedInterval()}\n";

# get just one interval by name
echo "{$watch->GetNamedInterval('1 second later')}\n";

# get another interval by name
echo "{$watch->GetNamedInterval('2 seconds later')}\n";

# get a result for an unknown (error) interval
echo "{$watch->GetNamedInterval('junk')}\n";

# enter an un-named interval, time for the 4 prior echo statements

# print results of all intervals so far

# wait another second

# print_r the results of all intervals

# end script