天天看点

性能对比

< 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  ,如需转载请自行联系原作者