1. Go to this page and download the library: Download mts7/php-execution-timer library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
class Benchmark
{
public function __construct(private \MtsTimer\TimerInterface $timer)
{
}
public function run(callable $callable): float
{
$this->timer->start();
$callable();
$this->timer->stop();
return $this->timer->getDuration();
}
}
class RunTheBenchmark
{
public function execute(): float
{
$timer = new \MtsTimer\Timer();
$benchmark = new Benchmark($timer);
return $benchmark->run([self::class, 'doNothing']);
}
public static function doNothing(): void
{
}
}
class BenchmarkTest
{
public function testRun(): void
{
$timer = new \MtsTimer\FixedTimer();
$benchmark = new Benchmark($timer);
$duration = $benchmark->run([RunTheBenchmark::class, 'doNothing']);
$this->assertSame($timer::DURATION, $duration);
}
}
shell
composer
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.