mirror of
https://github.com/jimeh/dlist.git
synced 2026-02-19 07:56:41 +00:00
- other general fixes to things a bit all over the place git-svn-id: file:///Users/jimeh/Desktop/dlist/trunk@12 a5845835-ea0f-0410-a762-dd0bfe9bfde8
46 lines
1.1 KiB
PHP
46 lines
1.1 KiB
PHP
<?php
|
|
|
|
class speedometer {
|
|
|
|
/*
|
|
|
|
Class: Speedometer v0.2
|
|
Created to simplify script execution statistics...
|
|
|
|
*/
|
|
|
|
var $digits = 6;
|
|
var $pattern = '%s'; // must contain %s
|
|
|
|
var $start;
|
|
var $time;
|
|
|
|
function speedometer ($digits=false) {
|
|
if ( !empty($digits) ) $this->digits = $digits;
|
|
$this->start = $this->getmicrotime();
|
|
}
|
|
|
|
// return with pattern
|
|
function end ($digits=false, $pattern=false) {
|
|
$end = $this->getmicrotime();
|
|
$digits = ( preg_match("/[0-9]{1,2}/", $digits) ) ? $digits : $this->digits ;
|
|
$pattern = ( stristr($pattern, '%s') != false ) ? $pattern : $this->pattern ;
|
|
$this->time = number_format( ($end - $this->start), $digits);
|
|
return str_replace('%s', $this->time, $pattern);
|
|
}
|
|
|
|
// return time only ignoring pattern
|
|
function term ($digits=false) {
|
|
$end = $this->getmicrotime();
|
|
$digits = ( preg_match("/[0-9]{1,2}/", $digits) ) ? $digits : $this->digits ;
|
|
return $this->time = number_format( ($end - $this->start), $digits);
|
|
}
|
|
|
|
function getmicrotime () {
|
|
list($usec, $sec) = explode(' ', microtime());
|
|
$r = floatval($usec) + floatval($sec);
|
|
return($r);
|
|
}
|
|
}
|
|
|
|
?>
|