测试方法
分别用asp.net、php执行一千万次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)." 毫秒";
?>
执行结果
为了得到更合理的数据,采用各执行5次(第一次执行除外),然后取平均值。如下为测试结果:
语言 执行时间 平均时间
asp.net 31ms 15ms 31ms 15ms 15ms 21ms
php 1470ms 1473ms 1476ms 1467ms 1490ms 1475ms
从以上测试结果看出,asp.net的执行时间比php快了70倍,这个测试结果是我一直没有想到的。
原文:
http://www.webkaka.com/blog/archives/the-speed-of-dotnet-php-and-asp.html