asp和php运行效率测试报告
顺便做了一下flash的测试。 (转载请注明出处 http://www.stonemx.com/blog)
以后在做一下asp.net 的测试。
测试环境:
OS 名称 Microsoft Windows XP Professional
版本 5.1.2600 Service Pack 2 内部版本号 2600
OS 制造商 Microsoft Corporation
系统类型 基于 X86 的 PC
处理器 x86 Family 6 Model 15 Stepping 13 GenuineIntel ~1995 Mhz
处理器 x86 Family 6 Model 15 Stepping 13 GenuineIntel ~1995 Mhz
BIOS 版本/日期 Phoenix Technologies LTD R1070Q0, 2007-7-31
SMBIOS 版本 2.4
硬件抽象层 版本 = "5.1.2600.2180 (xpsp_sp2_rtm.040803-2158)"
时区 中国标准时间
总的物理内存 1,024.00 MB
IIS:5.1
Apache/2.0.58 (Win32) PHP/4.4.2
运行 500500 次
php 用 0.224 秒
asp 用 0.999 秒
flash 用 1.237 秒
运行 4501500 次
php 用 2.003 秒
asp 用 3.000 秒
flash 用 11.25 秒
运行 8002000 次
php 用 3.602 秒
asp 用 4.999 秒
flash 用 26.70 秒
//////////////////////
flash代码
temp = 0;
time1 = getTimer();
for (var i:Number = 1; i<=3000; i++) {
for (var j:Number = 1; j<=i; j++) {
temp++;
}
}
time2 = getTimer();
sj = (time2-time1)/1000;
trace("运行 "+temp+" 次,用 "+sj+" 秒");
////////////////////////
asp代码
<%
dim t1,t2
t1=now()
temp=0
for i=1 to 4000
for j=1 to i
temp=temp+1
next
next
t2=now()
response.write "运行["&temp&"]次,这段ASP代码用了"&cstr(cdbl((t2-t1)*24*60*60))&"秒"
%>
//////////////////////
php代码
<?
class timer {
var $StartTime = 0;
var $StopTime = 0;
var $TimeSpent = 0;
function start(){
$this->StartTime = microtime();
}
function stop(){
$this->StopTime = microtime();
}
function spent() {
if ($this->TimeSpent) {
return $this->TimeSpent;
} else {
$StartMicro = substr($this->StartTime,0,10);
$StartSecond = substr($this->StartTime,11,10);
$StopMicro = substr($this->StopTime,0,10);
$StopSecond = substr($this->StopTime,11,10);
$start = doubleval($StartMicro) + $StartSecond;
$stop = doubleval($StopMicro) + $StopSecond;
$this->TimeSpent = $stop - $start;
return substr($this->TimeSpent,0,8)."秒";
}
}
}//end class timer;
// 这里是一个简单的例子:
$timer = new timer;
$timer->start();
$temp=0;
for($i=1;$i<=4000;$i++) for($j=0;$j<$i;$j++) $temp ++;
$timer->stop();
echo "循环 $temp 次,运行时间为 ".$timer->spent();
?>