Created
January 11, 2019 11:04
Revisions
-
pete-rai created this gist
Jan 11, 2019 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,61 @@ <? /* * A simple PHP timer class with interim marker support * * Released with the karmaware tag - https://pete-rai.github.io/karmaware * * Website : http://www.rai.org.uk * GitHub : https://github.com/pete-rai * LinkedIn : https://uk.linkedin.com/in/raipete * NPM : https://www.npmjs.com/~peterai * */ class Timer { protected $start; protected $mark; public function __construct () { $this->start = $this->mark = self::now (); } public static function now () { return microtime (true); } public function mark () { $now = self::now (); $tick = $now - $this->mark; $this->mark = $now; return $tick; } public function full () { return self::now () - $this->start; } } /* // --- test code only - leave commented out once working $timer = new Timer (); echo number_format ($timer->mark (), 6)."\n"; sleep (1); echo number_format ($timer->mark (), 6)."\n"; sleep (2); echo number_format ($timer->mark (), 6)."\n"; sleep (3); echo number_format ($timer->mark (), 6)."\n"; sleep (5); echo number_format ($timer->mark (), 6)."\n"; echo number_format ($timer->full (), 6)."\n"; */