此外,我没测试内存使用情况,不知道数组连接对内存使用会造成多大影响
}
////////////////////////////////////////////////////
//附1
////////////////////////////////////////////////////
{下面是用于对照的php脚本}
////////////////////////////////////////////////////
//--------------------------------------------------
//test.php
//使用字符连接
//对应于test-js2.asp和test-vbs2.asp
//--------------------------------------------------
<?
$t=gettimeofday();
for($i=0;$i<10000;$i++){
$s.=$i."\n";
}
echo($s."\n");
$now=gettimeofday();
echo(($now["sec"]-$t["sec"])*1000000+$now["usec"]-$t["usec"]);
?>
//--------------------------------------------------
////////////////////////////////////////////////////
//--------------------------------------------------
//test2.php
//直接输出
//对应于test-js3.asp和test-vbs3.asp
//--------------------------------------------------
<?
$t=gettimeofday();
for($i=0;$i<10000;$i++){
echo($i."\n");
}
$now=gettimeofday();
echo(($now["sec"]-$t["sec"])*1000000+$now["usec"]-$t["usec"]);
?>
//--------------------------------------------------
////////////////////////////////////////////////////
//--------------------------------------------------
//test3.php
//使用数组连接
//对应于test-js.asp和test-vbs.asp
//--------------------------------------------------
<?
$t=gettimeofday();
for($i=0;$i<10000;$i++){
$s[$i]=$i;
}
echo(implode("\n",$s));
$now=gettimeofday();
echo("<br>".(($now["sec"]-$t["sec"])*1000000+$now["usec"]-$t["usec"]));
?>
//--------------------------------------------------
////////////////////////////////////////////////////
//--------------------------------------------------
//test4.php
//使用零时文件
//对应于test-js4.asp,test-js5.asp,test-vbs4.asp和test-vbs5.asp
//--------------------------------------------------
<?
$t=gettimeofday();
$fp=fopen("temp.txt","w");
for($i=0;$i<10000;$i++){
fwrite($fp,$i."\n");
}
fclose($fp);
//readfile("temp.txt");
include("temp.txt");
$now=gettimeofday();
echo("<br>".(($now["sec"]-$t["sec"])*1000000+$now["usec"]-$t["usec"]));
?>
//--------------------------------------------------
////////////////////////////////////////////////////
<Celeron 466MHz 256MB SDRAM>
[Windows98SE Apache]
[InternetExplorer 6.0 Service Park 1]
//test.php(单位:微秒(北联网教程,专业提供视频软件下载)
……