for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php declare(strict_types=1);
namespace AlecRabbit\Tools\Internal;
use AlecRabbit\Accessories\Pretty;
class BenchmarkResult
{
/** @var float */
protected $mean;
protected $delta;
/** @var int */
protected $numberOfMeasurements;
protected $numberOfRejections;
public function __construct(float $mean, float $delta, int $numberOfMeasurements, int $numberOfRejections = 0)
$this->mean = $mean;
$this->delta = $delta;
$this->numberOfMeasurements = $numberOfMeasurements;
$this->numberOfRejections = $numberOfRejections;
}
public function getDeltaPercent(): float
return $this->getDelta() / $this->getMean();
/**
* @return float
*/
public function getDelta(): float
return $this->delta;
public function getMean(): float
return $this->mean;
public function getRejectionsPercent(): float
return $this->getNumberOfRejections() / $this->getNumberOfMeasurements();
* @return int
public function getNumberOfRejections(): int
return $this->numberOfRejections;
public function getNumberOfMeasurements(): int
return $this->numberOfMeasurements;
public function __toString(): string
return
sprintf(
'%s±%s',
Pretty::nanoseconds($this->getMean()),
Pretty::percent($this->getDeltaPercent())
);