I was reading an article online comparing PHP to ASP.NET the other day. The author, an Oracle employee, had some valid claims regarding PHP’s advantages when it comes to costs and flexibility, but he also had some unfounded claims that PHP was more efficient and faster. I beg to differ, so I ran some tests using a similar function for all three languages.
Test PlatformThe test was run on an AMD Athlon XP 2800+ with 2 GB of ram running Windows XP Professional SP2. We used a standard install of Internet Information Services and gave PHP the added benefit of installing Zend Optimizer v2.6.2. We used the php5isapi.dll to map and execute our PHP scripts.
- AMD Athlon XP 2800+ (2.08 GHz)
- 2 GB Ram
- Windows XP Professional SP2
- Internet Information Services v5.1
- Zend Optimizer v2.6.2
- PHP 5.1.2
- ASP 3.0
We wrote a similar script to test each language. It was a simple for loop that was programmed to loop 80 million times. You might need to increase the max execution settings in the php.ini file for PHP, or increase it programmatically. We chose to do it in the php.ini to make sure it was set correctly. The same holds true for ASP. You may need to increase the Server.ScriptTimeout value.
Some lines below might wrap, so be sure to check that before attempting to execute the code.ASP Code
<%
'Server.ScriptTimeout = 360
'Response.Buffer = False
Dim i
Dim startTime
Dim endTime
Dim totalTime
For x = 1 To 10
startTime = Now
Response.Write("Start Time: " & startTime & "<br />")
For i = 1 To 80000000
If i > 0 Then
End If
Next
endTime = Now
totalTime = endTime - startTime
Response.Write("End Time: " & endTime & "<br />")
Response.Write("Total time: " & Minute(totalTime) & ":" & Second(totalTime) & "<br /><br />")
Next
%>
PHP Code
<?php
function getmicrotime()
{
list($usec, $sec) = explode(" ",microtime());
return ((float)$usec + (float)$sec);
}
for ($x=0; $x < 10; $x++)
{
$number = 0;
$time_start = getmicrotime();
for ($i=0; $i < 80000000; $i++)
{
if ("hello" == "world") { }
}
$time_end = getmicrotime();
$time = $time_end - $time_start;
echo "Did 80M
additions in $time seconds";
}
?>
ASP.NET (VB.NET) Code
<%@ Language="VB" %>
<script runat="server" language="vb">
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)
Dim i As Long
Dim x As Int16
Dim startTime As Decimal
Dim endTime As Decimal
Dim totalTime As Decimal
For x = 1 To 10
startTime = Convert.ToDecimal(DateTime.Now.ToString("ss.fff"))
Response.Write("Start Time: " & startTime.ToString() & "<br />")
For i = 1 To 80000000
If "hello" Is "world" Then
End If
Next
endTime = Convert.ToDecimal(DateTime.Now.ToString("ss.fff"))
totalTime = endTime - startTime
Response.Write("End Time: " & endTime.ToString() & "<br />")
Response.Write("Total time: " & totalTime.ToString() & "<br /><br />")
Next
End Sub
Results
It’s no surprise that ASP.NET is the clear winner. The results that did surprise me were that Zend Optimizer consistently increased PHP’s performance by nearly 50%. That is a huge number. It is nonsense not to use PHP with the Optimizer according to our study.
The PHP results were roughly double of the numbers listed below without the Zend Optimizer running. And, as you can see, ASP’s performance is just plain bad.ASP.NET | PHP | ASP |
0.14 | 15.58716 | 33 |
0.125 | 15.92204 | 33 |
0.157 | 15.58681 | 35 |
0.124 | 15.58992 | 35 |
0.125 | 15.59410 | 33 |
0.125 | 15.93063 | 34 |
0.141 | 15.60623 | 33 |
0.125 | 15.60107 | 33 |
0.14 | 15.60247 | 34 |
0.125 | 16.14546 | 35 |
Results are in seconds
We welcome and performance enhancements and/or your own results. Just post your thoughts, results and any suggestions. I want to extend special thanks to Rufus Harvey for his technical prowess in helping put this test together!
- Ernest Carroll
No comments:
Post a Comment