本文整理汇总了PHP中Benchmark::bench方法的典型用法代码示例。如果您正苦于以下问题:PHP Benchmark::bench方法的具体用法?PHP Benchmark::bench怎么用?PHP Benchmark::bench使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Benchmark
的用法示例。
在下文中一共展示了Benchmark::bench方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: foreach
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;
}
}
set_time_limit(0);
ini_set('memory_limit', '256M');
Benchmark::bench();
示例2: explode
$words = explode(' ', $paragraph);
// Create a bunch of letter entries
$sequence = array();
for ($j = 0; $j < $elementNumber; $j++) {
$sequence[] = 'a' . $j;
}
$s = microtime(true);
for ($j = 0; $j < $total; $j++) {
foreach ($words as $word) {
in_array(strtolower($word), $sequence);
}
}
echo "in_array: " . (microtime(true) - $s) . "\n";
// Convert the array to a hash
Hashee::addBulk($sequence);
$s = microtime(true);
for ($j = 0; $j < $total; $j++) {
foreach ($words as $word) {
Hashee::in($word, $sequence);
}
}
echo "hashee: " . (microtime(true) - $s) . "\n";
echo "========================================\n";
}
}
$benchmark = new Benchmark();
$benchmark->bench(5);
$benchmark->bench(10);
$benchmark->bench(100);
$benchmark->bench(1000);
$benchmark->bench(10000);