php–ソースコード効率をテスト

関数:

begin($start);
report($start);

サンプルコード:

<?php
function begin(&$start) {
    $tmp = gettimeofday();
    $start = $tmp[usec];
}

function report($start) {
    $tmp = gettimeofday();
    $now = $tmp[usec];
    echo "time consuming: ";
    echo $now - $start;
    echo "<br>";
}

function getRandNum($length = 8) {
    $salt = substr(uniqid(rand()), -$length);
    return $salt;
}

$start = 0;
begin($start);
$str="";
while (strlen($str)< 10000)
{
    $str.=getRandNum(1);
}
report($start);

Source

Posted by arkgame