Created
February 25, 2014 09:58
-
-
Save yuktse/9206110 to your computer and use it in GitHub Desktop.
Helper codes in development
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function dump($var, $label = null){ | |
if($label) echo "<b>$label</b>"; | |
echo '<pre>'; | |
print_r($var); | |
echo '</pre>'; | |
} | |
class Runtime | |
{ | |
var $startTime = 0; | |
var $stopTime = 0; | |
private function getMicrotime() | |
{ | |
list($usec, $sec) = explode(' ', microtime()); | |
return ((float)$usec + (float)$sec); | |
} | |
function start() | |
{ | |
$this->startTime = $this->getMicrotime(); | |
} | |
function stop() | |
{ | |
$this->stopTime = $this->getMicrotime(); | |
} | |
private function spent() | |
{ | |
return number_format(($this->stopTime - $this->startTime) * 1000, 3); | |
} | |
function printResult($text = '<br>spent time: %s micro seconds', $return = false){ | |
if($return){ | |
return sprintf($text, $this->spent()); | |
}else{ | |
printf($text, $this->spent()); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment