예제 #1
0
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<title>関数の平均実行時間を測定したい</title>
</head>
<body>
<div>
<?php 
// PEAR::BEnchmark_Timerをインクルードする
require_once 'Benchmark/Iterate.php';
// 測定オブジェクトをnew演算子で作成する
$iterate = new Benchmark_Iterate();
// testArrayAdd()関数のベンチマークを実地する
$iterate->run(10, 'testArrayAdd');
$result1 = $iterate->get();
// testArrayAdd()関数の測定結果を表示する
echo '<p>[]構文で配列に値を追加した場合</p>';
echo '<ul>';
echo '<li>平均値: ' . $result1['mean'] . ' [sec]</li>';
echo '<li>全測定結果: <pre>';
print_r($result1);
echo '</pre></li>';
echo '</ul>';
// testArrayPush()関数のベンチマークを実地する
$iterate->run(10, 'testArrayPush');
$result2 = $iterate->get();
// testArrayPush()関数の計測kwっかを表示する
echo '<p>array_push()関数で配列に値を追加した場合</p>';
echo '<ul>';
echo '<li>平均値: ' . $result2['mean'] . ' [sec]</li>';
예제 #2
0
<?php

require_once "Benchmark/Iterate.php";
$test_array = create_random_array(100);
foreach (array('max', 'my_max') as $func) {
    $b = new Benchmark_Iterate();
    $b->run('10000', $func, $test_array);
    $result = $b->get();
    print "{$func}\t";
    printf("System + User Time: %1.6f\n", $result['mean']);
}
function create_random_array($size)
{
    $array = array();
    for ($i = 0; $i < $size; $i++) {
        $array[$i] = rand();
    }
    return $array;
}
function my_max($array)
{
    reset($array);
    $max = current($array);
    while ($el = next($array)) {
        if ($el > $max) {
            $max = $el;
        }
    }
    return $max;
}
<?php

require 'Benchmark/Iterate.php';
$timer = new Benchmark_Iterate();
// a sample function to time
function use_preg($ar)
{
    for ($i = 0, $j = count($ar); $i < $j; $i++) {
        if (preg_match('/gouda/', $ar[$i])) {
            // it's gouda
        }
    }
}
// another sample function to time
function use_equals($ar)
{
    for ($i = 0, $j = count($ar); $i < $j; $i++) {
        if ('gouda' == $ar[$i]) {
            // it's gouda
        }
    }
}
// run use_preg() 1000 times
$timer->run(1000, 'use_preg', array('gouda', 'swiss', 'gruyere', 'muenster', 'whiz'));
$results = $timer->get();
print "Mean execution time for use_preg(): {$results['mean']}\n";
// run use_equals() 1000 times
$timer->run(1000, 'use_equals', array('gouda', 'swiss', 'gruyere', 'muenster', 'whiz'));
$results = $timer->get();
print "Mean execution time for use_equals(): {$results['mean']}\n";
예제 #4
0
<?php

require_once "Benchmark/Iterate.php";
$bench = new Benchmark_Iterate();
require_once "../../Grace/Common.php";
$charset = $GLOBALS['db_charset'] = 'gbk';
//utf-8
$content = "今年春晚,我特地关注了赵本山的新小品《捐助》,这篇小品对弱势群体的不尊重并无改变,小品讲的是赵本山与其弟子扮演两个捐助者...";
/*phpwind*/
//$bench->run(50,"substrs",$content,30);
/*discuz*/
$bench->run(50, "C", $content, 30);
$result = $bench->get();
$bench->display();
//var_dump($result);
//asdfasfdasdf