Skip to content

Instantly share code, notes, and snippets.

@kobus1998
Created March 6, 2018 09:50
Show Gist options
  • Save kobus1998/14d3b09cd7efbc3adaa0be7090343aa1 to your computer and use it in GitHub Desktop.
Save kobus1998/14d3b09cd7efbc3adaa0be7090343aa1 to your computer and use it in GitHub Desktop.
Benchmark
<?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