Skip to content

Instantly share code, notes, and snippets.

@yuktse
Created February 25, 2014 09:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yuktse/9206110 to your computer and use it in GitHub Desktop.
Save yuktse/9206110 to your computer and use it in GitHub Desktop.
Helper codes in development
<?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