Created
May 13, 2014 07:03
-
-
Save mrspartak/f56ddad129af995c6d3b to your computer and use it in GitHub Desktop.
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
| <? | |
| class Bench | |
| { | |
| const defaultName = 'default'; | |
| private $_container = array(); | |
| public function start($name = self::defaultName) | |
| { | |
| $this->_container[$name] = array( | |
| 'time' => gettimeofday(true), | |
| 'memory' => memory_get_usage() | |
| ); | |
| } | |
| public function finish($name = self::defaultName) | |
| { | |
| list($startTime, $startMemory) = array_values( $this->_container[$name] ); | |
| $this->_container[$name] = array( | |
| 'time' => gettimeofday(true) - $startTime, | |
| 'memory' => memory_get_usage() - $startMemory | |
| ); | |
| } | |
| public function result($name = self::defaultName) | |
| { | |
| echo <<<EOT | |
| ---- $name <br> | |
| Time: {$this->getTime($name)} <br> | |
| Memory: {$this->getMemory($name)} <br> | |
| ---- <br> | |
| EOT; | |
| } | |
| public function getTime($name = self::defaultName) | |
| { | |
| return $this->_container[$name]['time']; | |
| } | |
| public function getMemory($name = self::defaultName) | |
| { | |
| return $this->_container[$name]['memory']; | |
| } | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage: