很多人在选择程序平台时都很纠结,因为现在程序平台太多,常用的有ASP.NET、PHP、ASP,那么今天我们就针对这两个程序进行一下运行速度的测试。
测试设备及环境
测试设备:自用笔记本
测试系统:Windows Server 2003企业版
运行环境:IIS6.0
测试方法
分别用asp.net、php和asp执行一千万次for循环,获得执行时间。如下为测试代码:
asp.net
System.DateTime startTime = System.DateTime.Now;
for (long i = 1; i < 10000000; i++)
{
}
System.DateTime endTime = System.DateTime.Now;
System.TimeSpan ts = endTime - startTime;
Response.Write("页面执行时间:" + ts.Milliseconds.ToString("0.000") + " 毫秒");
php
<?php
$start_time=microtime(true);
for($i=0; $i<10000000; $i++)
{
}
$end_time=microtime(true);
print "页面执行时间: ".round(($end_time-$start_time)*1000,1)." 毫秒";
?>
asp
<%
dim i
dim startime
startime=timer()
for i = 1 to 10000000
next
dim endtime
endtime=timer()
response.Write "页面执行时间:" & FormatNumber((endtime-startime)*1000,3) & "毫秒"
%>
执行结果
为了得到更合理的数据,采用各执行5次(第一次执行除外),然后取平均值。如下为测试结果:
语言 | 执行时间 | 平均时间 | ||||
asp.net | 31ms | 15ms | 31ms | 15ms | 15ms | 21ms |
php | 1470ms | 1473ms | 1476ms | 1467ms | 1490ms | 1475ms |
asp | 812ms | 828ms | 812ms | 812ms | 828ms | 818ms |
总结:在系统资源消耗方面,asp.net的优势再次凸显出来了,它对cpu的消耗比php和asp少很多,php对cpu的消耗比asp多一点,但差别不大;而对内存的消耗,三者差别并不大