note 59213 deleted from function.microtime by tularis
| From: | tularis@php.net | Date: | Sun, 22 Jun 2008 12:12:26 +0000 |
| Subject: | note 59213 deleted from function.microtime by tularis | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-140694@lists.php.net to get a copy of this message | ||
Note Submitter: saphir at trinity-lab dot com
----
A simple class in PHP5 allowing to know the execution time of a script :
<?php
class Timer
{
private $m_Start;
public function __construct()
{
$this->m_Start = 0.0;
}
private function GetMicrotime()
{
list($micro_seconds, $seconds) = explode(" ", microtime());
return ((float)$micro_seconds + (float)$seconds);
}
public function Init()
{
$this->m_Start = $this->GetMicrotime();
}
public function GetTime($Decimals = 2)
{
return number_format($this->GetMicrotime() - $this->m_Start, $Decimals, '.',
'');
}
}
$MyTimer = new Timer();
$MyTimer->Init();
sleep(1);
echo $MyTimer->GetTime();
// Output result -> 1.00
?>
Nico.