diff --git a/class/timer.php b/class/timer.php new file mode 100644 index 0000000..893df60 --- /dev/null +++ b/class/timer.php @@ -0,0 +1,87 @@ +startTimer = microtime(TRUE); + } + + /** + * end - Stores the end time + */ + Public function end() + { + $this->endTimer = microtime(TRUE); + } + + /** + * time - Returns the (end - start) times **NO FORMATING**. + * @return real Number value of the (end - start) times + */ + public function time() + { + return $this->endTimer-$this->startTimer; + } + + /** + * format_time - Returns the (end - start) times formated. + * @param string $format - Standard date() format Default = 'i:s.u'. + * @return string - date format of (end - start) times. + */ + public function format_time($format = 'i:s.u') + { + return $this->udate($format, $this->endTimer-$this->startTimer); + } + + /** + * avg_time - Returns the (end - start) times **NO FORMATING**. + * @param numeric $avg_count - Number to divide the (end - start) times from Default = 1 or No Division. + * @return numeric - Avg Number value of the (end - start) times + */ + public function avg_time($avg_count = 1) + { + return ($this->endTimer-$this->startTimer)/$avg_count; + } + + /** + * format_avg_time - Returns the (end - start) times formated. + * @param string $format - Standard date() format Default = 'i:s.u'. + * @param numeric $avg_count - Number to divide the (end - start) times from Default = 1 or No Division. + * @return numeric - Avg Number value of the (end - start) times + */ + public function format_avg_time($avg_count = 1, $format = 'i:s.u') + { + return $this->udate($format, ($this->endTimer-$this->startTimer)/$avg_count); + } +} +?> diff --git a/timer-example.php b/timer-example.php new file mode 100644 index 0000000..b4221e5 --- /dev/null +++ b/timer-example.php @@ -0,0 +1,18 @@ +start(); // <- Places a value for Start of Timer + sleep(5); // <- Pause + $timer->end(); // <- Places a value for End of Timer +// -- Output the Results + echo $timer->startTimer . '
'; + echo $timer->endTimer . '
'; + echo $timer->time() . '
'; + echo $timer->format_time() . '
'; + echo $timer->avg_time(5) . '
'; + echo $timer->format_avg_time(5); + // ===================================================