本文整理汇总了PHP中Timer::getAll方法的典型用法代码示例。如果您正苦于以下问题:PHP Timer::getAll方法的具体用法?PHP Timer::getAll怎么用?PHP Timer::getAll使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Timer
的用法示例。
在下文中一共展示了Timer::getAll方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: createSummary
/**
* Create benchmark summary.
*
* @throws BenchEx
*/
protected function createSummary()
{
$fastest = ['name' => '', 'value' => PHP_INT_MAX];
$leastMemory = ['name' => '', 'value' => PHP_INT_MAX];
$summary = $this->timer->getAll();
$ourSummary = [];
// Find fastest and least memory consuming one
foreach ($summary as $name => $values) {
$summary[$name]['time'] = $values['time'];
if ($fastest['value'] > $values['time']) {
$fastest['name'] = $name;
$fastest['value'] = $values['time'];
}
if ($leastMemory['value'] > $values['memory']) {
$leastMemory['name'] = $name;
$leastMemory['value'] = $values['memory'];
}
}
foreach ($summary as $name => $value) {
$ourSummary[$name] = ['time' => $value['time'], 'memory' => $value['memory'], 'to_fastest' => $value['time'] / $fastest['value'], 'to_least_memory' => $value['memory'] / $leastMemory['value'], 'per_sec' => ceil($this->iterations / $value['time'])];
}
$this->summary = $ourSummary;
uasort($this->summary, [$this, 'cmp']);
}
示例2: Timer
#!/usr/local/bin/php
<?php
/**
* Timer.class example script
*
* @author ktamas77 at gmail dot com
*/
date_default_timezone_set('UTC');
error_reporting(E_ALL);
require_once 'timer.class.inc.php';
$timer = new Timer();
$a = 0;
$timer->start('cycle');
for ($i = 0; $i < 100000; $i++) {
$a *= $i;
}
$timer->stop('cycle');
$timer->start('date');
for ($i = 0; $i < 10000; $i++) {
$d = date("Y-m-d H:i");
}
$timer->stop('date');
for ($i = 0; $i < 10; $i++) {
$timer->start("subloop");
for ($j = 0; $j < 1000000; $j++) {
$a = $i * $j;
}
$timer->stop("subloop");
}
var_dump($timer->getAll());