SitePoint Sponsor |
|
User Tag List
Results 1 to 25 of 133
Thread: PHP and .NET > Speed?
-
Nov 20, 2002, 08:00 #1
- Join Date
- Jun 2001
- Location
- Toronto, Canada
- Posts
- 9,123
- Mentioned
- 2 Post(s)
- Tagged
- 0 Thread(s)
PHP and .NET > Speed?
Hey,
This isn't a flame, a debate or anything, I'm just curious. On the .NET side of SitePoint, dhtmlgod (D to most of us) just wrote up a quick (half hour) demonstration to all of us of some of .NET's power.
It's very ruddy and very basic.
The location is here: http://www.oreosnbeer.com/sitepoint/sp1.aspx
There are a few things it does, but I'm mainly curious about the speed with which PHP would do the same thing, for my own knowledge. This isn't to show which is better or worse because you can't benchmark in this way. Different servers, differen't OS's, different loads and different DB's.
I'm just curious about execution time for PHP to do some of the similar types of things. You can even get the exact same database as D has, since he also does an XML output file which you can parse in (I hope).
Again, I'd like to stress that this is me being curious, so please no flames or anything else, thanks
J
-
Nov 20, 2002, 08:27 #2
- Join Date
- Mar 2001
- Location
- London | UK
- Posts
- 1,140
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
What is that showing? How fast it can read 1200 10 column rows from a database? I'm confused.
-
Nov 20, 2002, 08:29 #3
- Join Date
- Jun 2001
- Location
- Toronto, Canada
- Posts
- 9,123
- Mentioned
- 2 Post(s)
- Tagged
- 0 Thread(s)
Read, process and display, yes. It also does the same for transferring to an XML file as well.
-
Nov 20, 2002, 08:38 #4
- Join Date
- Mar 2001
- Location
- London | UK
- Posts
- 1,140
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
What sort of processing does it do on the data?
How much of a limit is placed on the data table? Ie. are the 10 million 50 column records to select the 1200 from?
If you give me a few parameters I'll try and replicate them this afternoon. Unfortunately I can only try it on a very slow and overloaded database server though.
Matt.
-
Nov 20, 2002, 08:41 #5
- Join Date
- Jun 2001
- Location
- Toronto, Canada
- Posts
- 9,123
- Mentioned
- 2 Post(s)
- Tagged
- 0 Thread(s)
All it's really doing is grabbing the data from the database (all of it, just the 1200 rows) and then putting it into the table, while timing it. There is additional information on your browser, .NET info and so on, but I don't really see why (or how) you'd repeat that without a tonne of coding.
Here's the source:
Code:<%@ Page Language="VB" ContentType="text/html" ResponseEncoding="iso-8859-1" trace="true" %> <%@ import Namespace="System.Data" %> <%@ import Namespace="System.Data.SQLClient" %> <%@ import Namespace="System.Web.Caching.Cache" %> <%@ OutPutCache Duration="60" VaryByParam="none" Location="server" %> <script language="VB" runat="server"> Sub Page_Load(byVal obj As Object, byVal e As EventArgs) Dim StartTime As DateTime = Now Dim DS As New DataSet Trace.Warn("Page_Load", "Look at me maw, I'm getting Data!") If ( cache.Get("example") is Nothing ) then Dim objSQLAdapter As SQLDataAdapter objSQLAdapter = New SQLDataAdapter("c_SPTestSpeed",ConfigurationSettings.AppSettings("connectionstring")) objSQLAdapter.Fill(DS, "example") cache.Insert("example", DS) Else DS = cType(cache.Get("example"),DataSet) End If test.DataSource = DS.Tables("example") test.DataBind() Trace.Warn("Page_Load", "Look at me maw, I just bound it to the Repeater control!") Dim endTime As DateTime = Now Dim theStop As String = formatNumber(endTime.Subtract(startTime).TotalSeconds, 2) loadTime.Text = "Loaded from database and send to browser in " & theStop & " seconds. Rendering HTML now:" loadTime2.Text = theStop End Sub </script> <html> <head> <title>ASP.NET Speed Test</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <link href="blah.css" rel="stylesheet" type="text/css"> </head> <body> <p>** Some side notes, this server isn't the best in the world, and application wide, dubugging is turned on, which also slows the server down slightly. Debugging is on cos I'm currently in development of my oreosnbeer.com site. If you scroll to the bottom of the page, you can find the trace info, which will give you a break down of the time and ASP.NET process. As you can see, the actual ASP.NET is processed in <ASP:Label id="loadTime2" runat="server" Text="Loading..." Font-Name="tahoma" Font-Size="13px" ></ASP:Label> . The rest of the time is YOUR browser, rendering the HTML (and trace). If you want to see the page without the trace, let me know. And just cos I'm soooo nice, click <a href="sp2.aspx">here</a> for a paged version! :o)</P> <ASP:Label id="loadTime" runat="server" Text="Loading..."></ASP:Label><br> <ASP:Repeater id="test" runat="server"> <HeaderTemplate> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr class="box1"> <td>productID</td> <td>productName</td> <td>supplierID</td> <td>categoryID</td> <td>quantityPerUnit</td> <td>unitPrice</td> <td>unitsInStock</td> <td>unitsOnOrder</td> <td>reorderLevel</td> <td>discontinued</td> </tr> </HeaderTemplate> <itemtemplate> <tr> <td><%# DataBinder.Eval(Container.DataItem, "productID")%></td> <td><%# DataBinder.Eval(Container.DataItem, "productName")%></td> <td><%# DataBinder.Eval(Container.DataItem, "supplierID")%></td> <td><%# DataBinder.Eval(Container.DataItem, "categoryID")%></td> <td><%# DataBinder.Eval(Container.DataItem, "quabtityPerUnit")%></td> <td><%# DataBinder.Eval(Container.DataItem, "unitPrice")%></td> <td><%# DataBinder.Eval(Container.DataItem, "unitsInStock")%></td> <td><%# DataBinder.Eval(Container.DataItem, "unitsOnOrder")%></td> <td><%# DataBinder.Eval(Container.DataItem, "reorderLevel")%></td> <td><%# DataBinder.Eval(Container.DataItem, "discontinued")%></td> </tr> </itemtemplate> <footertemplate> </table> </footertemplate> </ASP:Repeater> </body> </html>
-
Nov 20, 2002, 08:51 #6
- Join Date
- Jul 2001
- Location
- Scotland
- Posts
- 4,836
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
What is displayed in the XML file is whats in the database. Basically, someone was worried about the speed of using .NET to retrieve large volumes of data.
The ASP.NET script I knocked up takes it from the database, and displays it.
-
Nov 20, 2002, 08:56 #7
- Join Date
- Mar 2001
- Location
- London | UK
- Posts
- 1,140
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Ok, I'll see if I have any tables that are 10 column-ish and that I could just limit to a 1200 row read.
Where should I put the timing markers? After the read and iteration through putting the data into the templates (but before sending the buffer to the browser)?
-
Nov 20, 2002, 08:58 #8
- Join Date
- Jul 2001
- Location
- Scotland
- Posts
- 4,836
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
The ASP.NET time runs from when the page first starts to when its finished sending the data to the browser.
-
Nov 20, 2002, 09:03 #9
- Join Date
- Nov 2000
- Location
- Switzerland
- Posts
- 2,479
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
First things first - this line;
Code:<%@ OutPutCache Duration="60" VaryByParam="none" Location="server" %>
Will get back with some PHP...
-
Nov 20, 2002, 09:07 #10
- Join Date
- Jul 2001
- Location
- Scotland
- Posts
- 4,836
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Kind of, the page is cached on the server for 60 seconds, unless hard refresh is done (alt-f5 in ie).
I can take it out if you want.
-
Nov 20, 2002, 09:10 #11
- Join Date
- Jun 2001
- Location
- Toronto, Canada
- Posts
- 9,123
- Mentioned
- 2 Post(s)
- Tagged
- 0 Thread(s)
And even so doing makes little difference to the time. I did 15 hard refreshes, and all the times were between .07 and .15 seconds.
-
Nov 20, 2002, 09:13 #12
- Join Date
- Jul 2001
- Location
- Scotland
- Posts
- 4,836
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Try http://www.oreosnbeer.com/sitepoint/sp1t.aspx
Thats it without it.
-
Nov 20, 2002, 09:52 #13
- Join Date
- Nov 2000
- Location
- Switzerland
- Posts
- 2,479
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Next thing;
I suggest you put a second one of these at the end of the script (not 100% sure if that will work though - depends if .NET deals with <ASP: /> tags sequentially.
Code:<ASP:Label id="loadTime" runat="server" Text="Loading..."></ASP:Label><
The rest of the time is YOUR browser
It seems .NET is tell you this anyway near the end;
aspx.page End Render 0.449974 0.210817
-
Nov 20, 2002, 10:01 #14
- Join Date
- Jun 2001
- Location
- Toronto, Canada
- Posts
- 9,123
- Mentioned
- 2 Post(s)
- Tagged
- 0 Thread(s)
Harry,
It kind of sounds like you're attacking here, but anyways, the majority of the time is actually spent on caching the records, it seems:
aspx.page Begin SaveViewState 0.285676 0.188581
aspx.page End SaveViewState 0.285751 0.000075
And the render process is:
aspx.page End Render 0.424857 0.139072
So, a more realistic time is likely .21 seconds for the entirety of the operation, though D probably has more insight here.
I guess I'm going to need to assume the same level of depth in the PHP script though for timing and so on. I was looking for something simple not as a which is better or faster but just a general comparison becuase we can't do anything better than general given the environments and so on.
-
Nov 20, 2002, 10:47 #15
- Join Date
- Nov 2000
- Location
- Switzerland
- Posts
- 2,479
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Not attacking just pointing out what's before my eyes. As I read it, the total time it takes to finish everything is 0.424857 - the "From First(s)" column is when the script began so is a cummulative total. The "From Last(s)" seems to be the timee since the previous step.
Here's the code I've written.
My grindly slow box at work is now stuggling with XML and .sql files it can't handle but I'll get there.
PHP Code:<?php
class SpeedTest {
var $db; // Database resource
var $query; // Query resource
var $start; // Start time
function SpeedTest () {
$this->start=$this->getmicrotime();
$this->db=mysql_pconnect('localhost','user','pass'); // Enter correct values here
mysql_select_db('databasename',$this->db); // Enter correct dbname here
}
function getmicrotime(){
list($usec, $sec) = explode(" ",microtime());
return ((float)$usec + (float)$sec);
}
function fetch() {
$this->query=mysql_query('SELECT * FROM products',$this->db); // Perform query here
}
function getTime() {
return ($this->getmicrotime()-$this->start);
}
function getRow () {
if ( $row=mysql_fetch_array($this->query,MYSQL_ASSOC) )
return $row;
else
return false;
}
}
$sTest=new SpeedTest;
?>
<html>
<head>
<title>PHP Speed Test</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style>
body {
font-family: Verdana, Geneva, Arial, Helvetica, sans-serif;
font-size: 12px;
}
td {
font-family: Verdana, Geneva, Arial, Helvetica, sans-serif;
font-size: 12px;
}
th {
font-family: Verdana, Geneva, Arial, Helvetica, sans-serif;
font-size: 12px;
}
form {
font-family: Verdana, Geneva, Arial, Helvetica, sans-serif;
font-size: 12px;
}
input {
font-family: Verdana, Geneva, Arial, Helvetica, sans-serif;
font-size: 12px;
}
textarea {
font-family: Verdana, Geneva, Arial, Helvetica, sans-serif;
font-size: 12px;
}
select {
font-family: Verdana, Geneva, Arial, Helvetica, sans-serif;
font-size: 12px;
}
ul {
font-family: Verdana, Geneva, Arial, Helvetica, sans-serif;
font-size: 12px;
list-style-type: disc;
list-style-position: outside;
}
li {
font-family: Verdana, Geneva, Arial, Helvetica, sans-serif;
font-size: 12px;
}
ol {
font-family: Verdana, Geneva, Arial, Helvetica, sans-serif;
font-size: 12px;
list-style-type: upper-roman;
list-style-position: outside;
}
.small {
font-family: Verdana, Geneva, Arial, Helvetica, sans-serif;
font-size: 9px;
}
.big {
font-family: Verdana, Geneva, Arial, Helvetica, sans-serif;
font-size: 18px;
}
.bodystyle {
font-family: Verdana, Geneva, Arial, Helvetica, sans-serif;
font-size: 12px;
}
.box1 {
padding: 3px;
border-width: thin;
border-style: solid;
border-color: #CCCCCC #666666 #666666 #CCCCCC;
}
.box2 {
border-width: 3px;
border-style: solid;
padding: 5px;
}
</style>
</head>
<body>
<?php
$sTest->fetch();
?>
<p><b>Query Took: <?php print ($sTest->getTime()); ?></b></p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr class="box1">
<td>productID</td>
<td>productName</td>
<td>supplierID</td>
<td>categoryID</td>
<td>quantityPerUnit</td>
<td>unitPrice</td>
<td>unitsInStock</td>
<td>unitsOnOrder</td>
<td>reorderLevel</td>
<td>discontinued</td>
</tr>
<?php
while ( $row=$sTest->getRow() ) {
?>
<tr>
<td><?php print ( $row['productID']); ?></td>
<td><?php print ( $row['productName']); ?></td>
<td><?php print ( $row['supplierID']); ?></td>
<td><?php print ( $row['categoryID']); ?></td>
<td><?php print ( $row['quantityPerUnit']); ?></td>
<td><?php print ( $row['unitPrice']); ?></td>
<td><?php print ( $row['unitsInStock']); ?></td>
<td><?php print ( $row['unitsOnOrder']); ?></td>
<td><?php print ( $row['reorderLevel']); ?></td>
<td><?php print ( $row['discontinued']); ?></td>
</tr>
<?php
}
?>
<p><b>Page Took: <?php print ( $sTest->getTime() ); ?></b></p>
</table>
</body>
</html>
-
Nov 20, 2002, 10:59 #16
- Join Date
- Jul 2000
- Location
- Perth Australia
- Posts
- 1,717
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Shared server, shared perhaps with 150 other domains ?
simplistic but I am tired
http://www.koro.com.au/parse_sitepoint.php
-
Nov 20, 2002, 10:59 #17
- Join Date
- Jul 2001
- Location
- Scotland
- Posts
- 4,836
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Harry, your right, the original script was to test getting the data out the database, not rendering it. So for this test we can use the End Render time as the final tho that counts until the page has been downloaded into the browser.
Ok, so we got PHP, anyone willing to run it on their server? You'll need to make the database with 1232 records.
How about one that generates a pysical XML file with the data? (www.oreosnbeer.com/sitepoint/sp3.aspx)Last edited by dhtmlgod; Nov 20, 2002 at 11:01.
-
Nov 20, 2002, 11:32 #18
- Join Date
- Nov 2000
- Location
- Switzerland
- Posts
- 2,479
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
I'm done. 1232 records from MySQL (you're XML file) in under 0.01 seconds (usually around 0.005 seconds). Page rending (interestingly) takes longer (or at least so say the figures - you tell me which page takes longer to get...
This: http://www.oreosnbeer.com/sitepoint/sp1t.aspx
or this;
http://www.pinkgoblin.com/test/speedtest.php
The code (slightly modified since last version);
PHP Code:<?php
class SpeedTest {
var $db; // Database resource
var $query; // Query resource
var $start; // Start time
function SpeedTest () {
$this->start=$this->getmicrotime();
$this->db=mysql_pconnect('localhost','user','pass'); // Enter correct values here
mysql_select_db('database',$this->db); // Enter correct dbname here
}
function getmicrotime(){
list($usec, $sec) = explode(" ",microtime());
return ((float)$usec + (float)$sec);
}
function fetch() {
$this->query=mysql_unbuffered_query('SELECT * FROM products',$this->db); // Perform query here
}
function getTime() {
return ($this->getmicrotime()-$this->start);
}
function getRow () {
if ( $row=mysql_fetch_array($this->query,MYSQL_ASSOC) )
return $row;
else
return false;
}
}
$sTest=new SpeedTest;
?>
<html>
<head>
<title>PHP Speed Test</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style>
body {
font-family: Verdana, Geneva, Arial, Helvetica, sans-serif;
font-size: 12px;
}
td {
font-family: Verdana, Geneva, Arial, Helvetica, sans-serif;
font-size: 12px;
}
th {
font-family: Verdana, Geneva, Arial, Helvetica, sans-serif;
font-size: 12px;
}
form {
font-family: Verdana, Geneva, Arial, Helvetica, sans-serif;
font-size: 12px;
}
input {
font-family: Verdana, Geneva, Arial, Helvetica, sans-serif;
font-size: 12px;
}
textarea {
font-family: Verdana, Geneva, Arial, Helvetica, sans-serif;
font-size: 12px;
}
select {
font-family: Verdana, Geneva, Arial, Helvetica, sans-serif;
font-size: 12px;
}
ul {
font-family: Verdana, Geneva, Arial, Helvetica, sans-serif;
font-size: 12px;
list-style-type: disc;
list-style-position: outside;
}
li {
font-family: Verdana, Geneva, Arial, Helvetica, sans-serif;
font-size: 12px;
}
ol {
font-family: Verdana, Geneva, Arial, Helvetica, sans-serif;
font-size: 12px;
list-style-type: upper-roman;
list-style-position: outside;
}
.small {
font-family: Verdana, Geneva, Arial, Helvetica, sans-serif;
font-size: 9px;
}
.big {
font-family: Verdana, Geneva, Arial, Helvetica, sans-serif;
font-size: 18px;
}
.bodystyle {
font-family: Verdana, Geneva, Arial, Helvetica, sans-serif;
font-size: 12px;
}
.box1 {
padding: 3px;
border-width: thin;
border-style: solid;
border-color: #CCCCCC #666666 #666666 #CCCCCC;
}
.box2 {
border-width: 3px;
border-style: solid;
padding: 5px;
}
</style>
</head>
<body>
<?php
$sTest->fetch();
?>
<p><b>Query Took: <?php print ($sTest->getTime()); ?></b></p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr class="box1">
<td>productID</td>
<td>productName</td>
<td>supplierID</td>
<td>categoryID</td>
<td>quantityPerUnit</td>
<td>unitPrice</td>
<td>unitsInStock</td>
<td>unitsOnOrder</td>
<td>reorderLevel</td>
<td>discontinued</td>
</tr>
<?php
while ( $row=$sTest->getRow() ) {
?>
<tr>
<td><?php print ( $row['PRODUCTID']); ?></td>
<td><?php print ( $row['PRODUCTNAME']); ?></td>
<td><?php print ( $row['SUPPLIERID']); ?></td>
<td><?php print ( $row['CATEGORYID']); ?></td>
<td><?php print ( $row['QUANTITYPERUNIT']); ?></td>
<td><?php print ( $row['UNITPRICE']); ?></td>
<td><?php print ( $row['UNITSINSTOCK']); ?></td>
<td><?php print ( $row['UNITSONORDER']); ?></td>
<td><?php print ( $row['REORDERLEVEL']); ?></td>
<td><?php print ( $row['DISCONTINUED']); ?></td>
</tr>
<?php
}
?>
<p><b>Page Took: <?php print ( $sTest->getTime() ); ?></b></p>
</table>
</body>
</html>
I think we can call that a pelvic thrust for both PHP and MySQL.
PS: Please note that's running on a shared server. Could probably do better on a dedicated server.Last edited by HarryF; Nov 20, 2002 at 11:34.
-
Nov 20, 2002, 11:36 #19
- Join Date
- Jun 2001
- Location
- Toronto, Canada
- Posts
- 9,123
- Mentioned
- 2 Post(s)
- Tagged
- 0 Thread(s)
Again, I wasn't into comparing speeds as we would need to define baselines for:
- hardware
- OS
- webserver
- database
Independently, and even just analyzing the languages it is clear D's example wasn't ever for performance (dunno if yours is). Also, D is on a very heavily shared server, and [edit: D removed tracing, my bad].
Anyways, so final page load and query times are what for each? Again, this is curiosity and I'll be extremely disappointed if this comes up in any x vs y discussions
-
Nov 20, 2002, 12:21 #20
- Join Date
- Sep 2000
- Location
- Halmstad, Sweden
- Posts
- 7,400
- Mentioned
- 1 Post(s)
- Tagged
- 0 Thread(s)
Originally posted by HarryF
I'm done. 1232 records from MySQL (you're XML file) in under 0.01 seconds (usually around 0.005 seconds).
I hardly doubt this has anything to do with .NET or PHP at all, but rather between mySQL and MSSQL. mySQL is faster than satan on pure SELECT performance, and I've never seen get beaten by anything but plain text.Mattias Johansson
Short, Swedish, Web Developer
Buttons and Dog Tags with your custom design:
FatStatement.com
-
Nov 20, 2002, 12:45 #21
- Join Date
- Aug 2001
- Location
- London
- Posts
- 2,475
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
I'm surprised by those results, just curious now how php compares to jsp after dot net gave them a thrashing
ps dhtmlgod which host are you with?
-
Nov 20, 2002, 12:55 #22
- Join Date
- Jun 2001
- Location
- Toronto, Canada
- Posts
- 9,123
- Mentioned
- 2 Post(s)
- Tagged
- 0 Thread(s)
He's with www.adehost.com. Actually a very good company, especially for the price
-
Nov 20, 2002, 14:10 #23
- Join Date
- Nov 2001
- Location
- Atlanta, GA, USA
- Posts
- 5,011
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally posted by M. Johansson
I hardly doubt this has anything to do with .NET or PHP at all, but rather between mySQL and MSSQL. mySQL is faster than satan on pure SELECT performance, and I've never seen get beaten by anything but plain text.
Easy to even the field, though (at least on a superficial level)... anyone care to use dhtmlgod's example using ASP.NET and mySQL?Using your unpaid time to add free content to SitePoint Pty Ltd's portfolio?
-
Nov 20, 2002, 14:14 #24
- Join Date
- Jun 2001
- Location
- Toronto, Canada
- Posts
- 9,123
- Mentioned
- 2 Post(s)
- Tagged
- 0 Thread(s)
This was never, ever, meant to be a true comparison
The hardware is different, OS is different, webserver is different AND database is different. Since we can't ever get a decent baseline it was just curiosity.
Ah well, I don't care, I'M HAVING A BABY!!!!!!!!
-
Nov 20, 2002, 14:21 #25
- Join Date
- Sep 2000
- Location
- Halmstad, Sweden
- Posts
- 7,400
- Mentioned
- 1 Post(s)
- Tagged
- 0 Thread(s)
Originally posted by Jeremy W.
Ah well, I don't care, I'M HAVING A BABY!!!!!!!!Mattias Johansson
Short, Swedish, Web Developer
Buttons and Dog Tags with your custom design:
FatStatement.com
Bookmarks