Created
September 18, 2012 17:45
-
-
Save scarstens/3744576 to your computer and use it in GitHub Desktop.
PHP Benchmark Timer
This file contains 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
$timer = new timer(1); // constructor starts the timer, so no need to do it ourselves | |
/* | |
... mysql query ... | |
*/ | |
$query_time = $timer->get(); | |
/* | |
... page processing ... | |
*/ | |
$processing_time = $timer->get(); | |
class timer { | |
var $start; | |
var $pause_time; | |
/* start the timer */ | |
function timer($start = 0) { | |
if($start) { $this->start(); } | |
} | |
/* start the timer */ | |
function start() { | |
$this->start = $this->get_time(); | |
$this->pause_time = 0; | |
} | |
/* pause the timer */ | |
function pause() { | |
$this->pause_time = $this->get_time(); | |
} | |
/* unpause the timer */ | |
function unpause() { | |
$this->start += ($this->get_time() - $this->pause_time); | |
$this->pause_time = 0; | |
} | |
/* get the current timer value */ | |
function get($decimals = 8) { | |
return round(($this->get_time() - $this->start),$decimals); | |
} | |
/* format the time in seconds */ | |
function get_time() { | |
list($usec,$sec) = explode(' ', microtime()); | |
return ((float)$usec + (float)$sec); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment