Created
March 6, 2018 09:50
-
-
Save kobus1998/14d3b09cd7efbc3adaa0be7090343aa1 to your computer and use it in GitHub Desktop.
Benchmark
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 characters
<?php | |
class Benchmark | |
{ | |
public $time; | |
private $startTime; | |
private $stopTime; | |
public function go($callback) | |
{ | |
$this->start(); | |
$callback(); | |
$this->stop(); | |
return " | |
=== | |
".round($this->time,2). " seconds | |
=== | |
"; | |
} | |
private function start() | |
{ | |
$this->startTime = microtime(true); | |
} | |
private function stop() | |
{ | |
$this->stopTime = microtime(true); | |
$this->set(); | |
} | |
private function set() | |
{ | |
$this->time = $this->stopTime - $this->startTime; | |
} | |
public function get() | |
{ | |
return $this->time; | |
} | |
} | |
$benchmark = new Benchmark(); | |
echo $benchmark->go(function () { | |
sleep(2); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment