Guest User

Untitled

a guest
Sep 23rd, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.72 KB | None | 0 0
  1. <?php
  2. class Timer {
  3.     private $func, $iterations, $start, $stop;
  4.     public function __construct($func = false, $iterations = 500) {
  5.         $args = func_get_args();
  6.  
  7.         if(is_callable($args[0])) {
  8.             $this->func = $func;
  9.             $this->iterations = is_int($args[1]) ? $iterations : 500;
  10.  
  11.             $this->execute();
  12.         }
  13.  
  14.     }
  15.     private function execute() {
  16.         $this->start();
  17.         for($i = 0; $i <= $this->iterations; $i++) {
  18.             $this->func();
  19.         }
  20.         $this->stop();
  21.     }
  22.     public function start() {
  23.         $this->start = microtime(true)
  24.         return $this->start;
  25.     }
  26.     public function stop() {
  27.         $this->stop = microtime(true);
  28.         return $this->stop;
  29.     }
  30.     public function getAverage(){
  31.         return ($this->stop - $this->start) / $iterations;
  32.     }
  33. }
  34. ?>
Add Comment
Please, Sign In to add comment