close
用來計算程式所需的執行時間。
PHP CODE:
<?php
function caclutime(){
$time = explode( " ", microtime());
$usec = (double)$time[0];
$sec = (double)$time[1];
return $sec + $usec;
}
?>
PHP計算程式執行時間程式例子:
<?php
function caclutime(){
$time = explode( " ", microtime());
$usec = (double)$time[0];
$sec = (double)$time[1];
return $sec + $usec;
}
?>
<?php
function caclutime(){
$time = explode( " ", microtime());
$usec = (double)$time[0];
$sec = (double)$time[1];
return $sec + $usec;
}
?>
<br>
<?php
$t=0;
$begin_time=caclutime();
//for 初始寫在條件式中
for ($i=0;$i<100000 ;$i++ ) { $t++;}
$end_time=caclutime();
$total=$end_time-$begin_time;
echo "$total 秒 for 執行 $t 次:";//顯示結果
?>
<br>
<?php
$t=0;
$begin_time=caclutime();
//while先初始化
$i=0;
while($i++<100000){ $t++; }
$end_time=caclutime();
$total=$end_time-$begin_time;
echo "$total 秒 while 執行 $t 次:";//顯示結果
?>
全站熱搜
留言列表