|
|
|
|
|
|
| |
This class starts a timer on instantiation. You can then stop it whenever you want by calling the timer::timer_stop() function. Show the time between instantiation and stopping by calling timer::timer_show() function.
Both stopping and showing the timer is done by the timer::timer_stop_show() function. This gives you the time including milliseconds to 3 decimal places, but you can pass timer_show() and timer_stop_show() functions a number of decimal places to display instead.
Timer Class
@author Ben Barnett <ludge@spymac.com>
@version 1.1
Timing Class
When a new object is created, it immediately starts timing and only stops when
you call objectname->endtimer(). The calculations for finding time taken are not carried
out until they are ready to be displayed to avoid them effecting the timer results. Although I
doubt they'd make much difference.
| <?php
class timer
{
/**
* The start time of the timer
*/
var $starttime;
/**
* The end time of the timer
*/
var $endtime;
/**
* Constructor begins timer.
*/
function timer()
{
$this->starttime = microtime();
}
/**
* Stops the timer.
*/
function timer_stop()
{
$this->endtime = microtime();
}
/**
* Calculates and returns the time taken.
*
* Explodes the start and end time into arrays then totals up each array. Subtracts
* the start time from the end time to give time taken to the number of decimal places
* passed as a parameter.
*
* @param integer $decimals The number of decimal places to show in the timer. Default is 3.
* @return float The time taken between instantiating the class and stopping the timer.
*/
function timer_show($decimals=3)
{
// Make sure the parameter is an integer
$decimals = intval($decimals);
// Restrict decimal places to 8
if($decimals > 8)
{
$decimals = 8;
}
// Decimal places cannot be below zero!
if($decimals < 0)
{
$decimals = 0;
}
// Explode into arrays so that the decimal and UNIX timestamp can be added
$starttime = explode(" ", $this->starttime);
$endtime = explode(" ", $this->endtime);
// Add the decimal to the timestamp
$starttime = (float)$starttime[1] + (float)$starttime[0];
$endtime = (float)$endtime[1] + (float)$endtime[0];
return number_format($endtime - $starttime, $decimals);
}
/**
* Stop and show the timer.
*
* Combines the stop and show timer functions.
*
* @param integer $decimals The number of decimal places to show in the timer. Default is 3.
* @return float The time taken between instantiating the class and stopping the timer.
*/
function timer_stop_show($decimals=3)
{
$this->timer_stop();
return $this->timer_show($decimals);
}
}
?> | | |
|
| pcCalendar class - Allows for the creation of calendars in HTML pages. All output functions can be easily overridden, refer to article 1471 for an example.
Categories : PHP, Date Time, Calendar, PHP Classes | | | Open and Close your website in fixed times . Categories : PHP, PHP Classes, Cron, Date Time | | | Example of using the pcCalendar class, article 1468 on weberdev.com. Calendar example. Categories : PHP, Date Time, PHP Classes, Calendar | | | A PHP Calendar function with CSS : add a cool calendar to any php page by just adding a calendar class based function. Categories : PHP, PHP Classes, Calendar, Date Time | | | Validator - A PHP class that can can be used for validating Email IDs and Dates Categories : PHP, PHP Classes, Data Validation, Email, Date Time | | | A time measuring and performance benchmarking class Categories : PHP, PHP Classes, Testing, Debugging, Date Time | | | Bs_StopWatch is a class to measure time intervals in microseconds.
Categories : PHP, Date Time, PHP Classes | | | Customizable Calendar Class Categories : HTML and PHP, Date Time, PHP, PHP Classes, Calendar | | | Code Execution Time Calculator Categories : PHP, PHP Classes, Date Time | | | a class that uses microtime() to provide easy calculation of elapsed times
Categories : Date Time, PHP, PHP Classes | | | file class , uploade file , download file already uploaded on another website Categories : PHP, PHP Classes, Filesystem, Web Services | | | Authorize.net AIM Interface Class v1.0.0 Categories : PHP, PHP Classes, Ecommerce, Payment Gateways | | | News management class Categories : PHP, PHP Classes, Beginner Guides | | | The class to check load time of your script
VERY usefull for relatively slow applications, but not only.. Categories : PHP, PHP Classes, Debugging | | | Expose - PHP template engine, supports server and client-sided caching,a plugin system, multiple languages, template script language is based on PHP itself. Categories : PHP, PHP Classes, Templates, Complete Programs | |
|
|
|