In this post LINQ to SQL Vs ADO.Net
Performance Test – Calling Stored Procedures we, shall compare the
performance of LINQ to SQL and ADO.Net in executing a stored procedure
call. This stored procedure returns 1000 rows; the result set returned by the
procedure is bound to a GridView control.
Asp.Net provides a number
of Data Access Technologies, like ADO.Net, LINQ-to-SQL, Entity Framework
etc, each one of these technologies has its own advantages and disadvantages, and
while designing an application; we need to identify the appropriate data access
technology to achieve maximum efficiency.
The configuration of the system used to
perform the evaluation is as follows.
OS
|
Windows XP Professional 2002 SP3
|
Processor
|
Pentium® D 2.66 GHz
|
RAM
|
3 GB
|
The performance test was carried out for 25
iterations with both ADO.net and LINQ-to-SQL; the results of the test
are as follows.
ADO.Net Average time: 17.72
Milliseconds
LINQ-to-SQL Average time: 15.8 Milliseconds
The test results show that both LINQ to SQL and ADO.Net perform more or less similar with LINQ-to-SQL having a slight edge over ADO.Net.
The code used to perform the test is as
follows
ADO.Net
SqlConnection objConn;
SqlCommand objCmd;
SqlDataAdapter objDA;
DataSet dsEmp;
Stopwatch timer;
string strQuery = string.Empty;
timer =
new Stopwatch();
timer.Start();
string strConn = ConfigurationManager.ConnectionStrings["EmployeesConnectionString"].ToString();
objConn
= new SqlConnection(strConn);
strQuery
= "GetEmployees";
objCmd
= new SqlCommand(strQuery,
objConn);
objCmd.CommandType
= CommandType.StoredProcedure;
objDA =
new SqlDataAdapter(objCmd);
dsEmp =
new DataSet();
objDA.Fill(dsEmp,
"dtEmp");
grdEmployees.DataSource
= dsEmp.Tables["dtEmp"].DefaultView;
grdEmployees.DataBind();
timer.Stop();
lblExecutionTime.Text = "Execution
Time (Milliseconds):" + timer.ElapsedMilliseconds.ToString();
LINQ to SQL
EmployeeClassesDataContext dbContext = new EmployeeClassesDataContext();
Stopwatch timer;
timer =
new Stopwatch();
timer.Start();
var empList = dbContext.GetEmployees();
grdEmployees.DataSource
= empList;
grdEmployees.DataBind();
timer.Stop();
lblExecutionTime.Text = "Execution
Time (Milliseconds):" + timer.ElapsedMilliseconds.ToString();
That’s it we have evaluated the performance
of ADO.net and LINQ-to-SQL in executing a stored Procedure which returns
1000 rows.
RELATED POST
No comments:
Post a Comment