< DOCTYPE html PUBLIC -WCDTD XHTML StrictEN httpwwwworgTRxhtmlDTDxhtml-strictdtd>
現在開發B/S這種模式時我一般會首選是JAVA,不過以前也曾經用過ASP,PHP,.NET,前天我做了一個加法運算的性能測試,發現JAVA确實在性能上很突出,當然dotnet也錯,java的性能在很大程度上是看他用的jdk版本,如果用jdk1.6性能要遠遠高于jdk1.4,不過即使用jdk1.6,其性能也隻能和dotnet(dotnet我也是用最新dotnetframeworks 3)相當,不知道是不是支援的容器有點關系,我用的是tomcat,用其它的可能要快一點吧!至于php,asp他們兩個測試性能遠遠不能和java和dotnet相比。現在把測試代碼給列出來:
jsp:
<%
long timeStart = System.currentTimeMillis();
int i=0;
int count;
while(i<500000000)i++;
long timeEnd = System.currentTimeMillis();
long timeUse=timeEnd-timeStart;
out.print(timeUse);
%>
dotnet vb:
<%@ Page language="vb" %>
dim t1 as Single,t2 as Single
dim lsabc as Integer,thetime as Integer,i as Integer
t1=timer
for i=1 to 500000000
lsabc= 1 + 1
next
t2=timer
thetime=cstr(int(( (t2-t1)*10000 )+0.5)/10)
Response.Write ("...已完成!<font color=red>" & thetime & "毫秒</font>。<br>")
asp:
dim t1,t2,thetime,i,lsabc
Response.Write "...已完成!<font color=red>" & thetime & "毫秒</font>。<br>"
php:
<?
function getmicrotime()
{
list($usec, $sec) = explode(" ",microtime());
return ((float)$usec + (float)$sec);
}
$time_start=getmicrotime();
for($index=0;$index<=500000000;$index++);
{
$count=1+1;
}
$time_end=getmicrotime();
$time=$time_end-$time_start;
$time=round($time*1000);
echo($time);
?>
總結:
php應該還是可以優化的,因為他要調用一個函數。asp中如果你不用dim那些變量就會發現速度會更慢,dotnet中也一樣,而且dotnet如果不定義具體什麼類型的變量,是變體型變量的話,在性能上也會受到影響。從性能上來說dotnet和jsp要遠遠高出php,asp幾百倍。
本文轉自 netcorner 部落格園部落格,原文連結:http://www.cnblogs.com/netcorner/archive/2006/12/22/2912458.html ,如需轉載請自行聯系原作者