Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Timer {
- private $func, $iterations, $start, $stop;
- public function __construct($func = false, $iterations = 500) {
- $args = func_get_args();
- if(is_callable($args[0])) {
- $this->func = $func;
- $this->iterations = is_int($args[1]) ? $iterations : 500;
- $this->execute();
- }
- }
- private function execute() {
- $this->start();
- for($i = 0; $i <= $this->iterations; $i++) {
- $this->func();
- }
- $this->stop();
- }
- public function start() {
- $this->start = microtime(true)
- return $this->start;
- }
- public function stop() {
- $this->stop = microtime(true);
- return $this->stop;
- }
- public function getAverage(){
- return ($this->stop - $this->start) / $iterations;
- }
- }
- ?>
Add Comment
Please, Sign In to add comment