I'm thinking about using ASP.NET in a new project I'm starting and I'm wondering if it's faster than classic ASP. I've been using classic for years, and never ran into any problems, but I really want to pick the fastest out of the three.
Thanks for your help!
Fastest to run? Fastest to develop a site with? Fastest to solve problems when they occur? Fastest to train new developers up on?
All will run fast enough if well written. All will run dog slow if not. I think you need to consider how valid your objective here is.
I was arguing about this topic with one of my friends. He believes that Classic ASP is much faster. So I googled and found this old question and nothing else. So I decided to run a speed test comparing ASP.NET and Classic ASP and the results are amazingly unbelievable!
I tested in an equal environment with these two cases:
1- using ADODB to query an SQL database table with more than 500.000 rows. with both asp.net and classic asp. It takes 133000ms for ASP.NET It takes 5000ms for Classic ASP
The ASP.NET code:
var conn = new ADODB.Connection();
conn.Open(@"Driver={SQL Server};Server=.\sql2008;Database=Db;User Id=sa;Password=pwd");
ADODB.Recordset rs = new ADODB.Recordset();
var sql = "SELECT * From tRep";
rs.Open(sql, conn, ADODB.CursorTypeEnum.adOpenStatic, ADODB.LockTypeEnum.adLockBatchOptimistic, 0);
while (rs.EOF == false)
rs.MoveNext();
Classic ASP code:
Set dbconn = CreateObject("ADODB.Connection")
dbconn.open "Driver={SQL Server};Server=.\sql2008;Database=Db;User Id=sa;Password=pwd"
set rs=dbconn.execute("SELECT * From trep")
while not rs.eof
rs.movenext
wend
dbconn.Close
2- My second test was same as the first one, using ADO.NET in both ASP.NET and Classic ASP(using a ComVisible .Net Assembly)
It takes 2155ms for ASP.NET to query the database and 1745ms for Classic ASP Here are my codes:
//ASP.NET Codes:
var i = 0;
var result = "";
double av = 0;
var runs = 50;
for (var j = 0; j < runs; j++)
{
var t1 = DateTime.Now;
var CS = @"data source=.\sql2008;initial catalog=Db;user id=sa;password=pwd;multipleactiveresultsets=True;";
var Query = "SELECT * From trep";
using (var conn = new SqlConnection(CS))
{
conn.Open();
using (var cmd = new SqlCommand(Query, conn))
{
using (var dr = cmd.ExecuteReader(CommandBehavior.CloseConnection))
{
if (dr.HasRows)
{
while (dr.Read())
{
var x = dr[0];
i++;
}
}
}
}
}
var t2 = DateTime.Now;
av = av + (t2 - t1).TotalMilliseconds;
result += "\r\nRun " + (j + 1) + ": " + (t2 - t1).TotalMilliseconds;
}
result += result + "\r\nAVG=" + (av / runs / 1000);
'Classic ASP Codes:
Set db = CreateObject("ADONET.AdoDotNet")
runs=50
av=0
for i=1 to runs
t1=timer()
xx= db.ExecuteQuery("SELECT * From trep","data source=.\sql2008;initial catalog=Db;user id=sa;password=pwd;multipleactiveresultsets=True")
t2=timer()
response.write("Run "&i&" Total Time(sec):"&(t2-t1)&"<br>")
av=av+t2-t1
next
g=av/runs
response.write("avg:"&g&"<br>")
And the ComVisible ADONET.AdoDotNet class is:
[ComVisible(true)]
public class AdoDotNet
{
[ComVisible(true)]
public int ExecuteQuery(string Query,string CS)
{
var i = 0;
//var ds = new DataSet();
using (var conn=new SqlConnection(CS))
{
conn.Open();
using(var cmd = new SqlCommand(Query, conn))
{
using (var dr = cmd.ExecuteReader(CommandBehavior.CloseConnection))
{
if (dr.HasRows)
{
while (dr.Read())
{
var x = dr[0];
i++;
}
}
}
}
}
return i;
}
}
Interesting point is the more you increase the runs, it take more time for ASP.NET to execute the codes!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With