Timer.php 351 B

1234567891011121314151617181920212223
  1. <?php
  2. namespace demo\Services;
  3. class Timer {
  4. const SCALE = 1E4;
  5. protected $t0;
  6. protected function __construct($t0) {
  7. $this->t0 = $t0;
  8. }
  9. public static function create() {
  10. return new static(microtime(true));
  11. }
  12. public function delay() {
  13. $diff = microtime(true) - $this->t0;
  14. return round($diff * static::SCALE);
  15. }
  16. }