Esempio n. 1
0
 /**
  * @param $duration
  * @param $ops
  * @param $expected
  *
  * @dataProvider toStringProvider
  */
 public function testToString($duration, $ops, $expected)
 {
     $result = new Result($duration, $ops, new Method(null, ''), new Parameter(null, ''));
     $ur = new UnitResult();
     $ur->add($result);
     $this->assertEquals($expected, $result->getNormalizedOperationsPerUnit($ur));
 }
Esempio n. 2
0
 /**
  * Sort methods best score first.
  */
 private function sortByMethodScore()
 {
     uasort($this->methods, function ($first, $second) {
         $aScore = $this->result->getMethodScore($first);
         $bScore = $this->result->getMethodScore($second);
         if ($aScore === $bScore) {
             return 0;
         }
         return $aScore < $bScore ? -1 : 1;
     });
 }
Esempio n. 3
0
 public function getNormalizedOperationsPerUnit(UnitResult $unitResult)
 {
     $allResults = Arrays::flatten($unitResult->getResults());
     $minOpsPerSec = PHP_INT_MAX;
     /** @var Result $result */
     foreach ($allResults as $result) {
         $minOpsPerSec = min($minOpsPerSec, $result->getOperationsPerSecond());
     }
     $opsPerUnit = $this->getOperationsPerSecond();
     $unit = 's';
     if ($minOpsPerSec < 1) {
         $minOpsPerSec *= 60;
         $opsPerUnit *= 60;
         $unit = 'm';
     }
     if ($minOpsPerSec < 1) {
         $opsPerUnit *= 60;
         $unit = 'h';
     }
     return $this->formatNumber($opsPerUnit) . '/' . $unit;
 }