public static function bench() { echo "Benchmark PHP-" . PHP_VERSION . PHP_EOL; echo "OS: " . PHP_OS . PHP_EOL; echo "Info: " . php_uname('a') . PHP_EOL; echo str_repeat('=', 40) . PHP_EOL; $max = -10; $min = 10; $count = 14000000; $rounds = 10; $class = new Benchmark(); $allStatistics = array(); for ($i = 0; $i < $rounds; $i++) { self::$statistics = []; $total = 0; echo "Round " . ($i + 1) . "...." . PHP_EOL; $total += Benchmark::benchCall($class, 'math', $count); $total += Benchmark::benchCall($class, 'methodCallEmpty', $count); $total += Benchmark::benchCall($class, 'methodCallBool', $count); $count = 140000; $total += Benchmark::benchCall($class, 'arrayAppendInt', $count); $total += Benchmark::benchCall($class, 'arrayAppendString', $count); $total += Benchmark::benchCall($class, 'readClassConst', $count); $total += Benchmark::benchCall($class, 'readClassConstBySelf', $count); echo "end" . PHP_EOL; echo PHP_EOL; $min = min($min, $total); $max = max($max, $total); $allStatistics[] = self::$statistics; } $table = new Table(); $table->setHeaders(array('Test', 'Min', 'Max', 'Avg')); foreach ($allStatistics[0] as $key => $row) { $minRow = 10; $maxRow = -10; $avgRow = 0; for ($i = 0; $i < $rounds; $i++) { $value = $allStatistics[$i][$key]; $minRow = min($minRow, $value); $maxRow = max($maxRow, $value); $avgRow += $value; } $table->addRow([$key, $minRow, $maxRow, $avgRow / $rounds]); } /** * 0.1 - 60 000 * $min - */ $perfect = 0.1; $perfectScore = 60000; echo str_repeat('=', 40) . PHP_EOL . PHP_EOL; $table->printTable(); echo PHP_EOL; echo "Max: " . $max . PHP_EOL; echo "Min: " . $min . PHP_EOL; $score = $perfect / $min * $perfectScore; echo "Score: " . number_format($score, 0, ' ', 'k') . PHP_EOL; }