當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Timer::getAll方法代碼示例

本文整理匯總了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']);
 }
開發者ID:rzajac,項目名稱:phpbench,代碼行數:29,代碼來源:Bench.php

示例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());
開發者ID:ktamas77,項目名稱:phptimer,代碼行數:30,代碼來源:timer_example.php


注:本文中的Timer::getAll方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。