コード例 #1
0
ファイル: Bench.php プロジェクト: rzajac/phpbench
 /**
  * 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
0
ファイル: timer_example.php プロジェクト: ktamas77/phptimer
#!/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());