Monday, May 28, 2012

LINQ to SQL Vs ADO.Net Performance Test - UPDATE


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, while designing an application; we need to identify the appropriate data access technology to achieve maximum efficiency.



Here we shall evaluate the data access performance of ADO.net and LINQ-to-SQL to execute an UPDATE query with 8 Columns.
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:              595 Microseconds
LINQ-to-SQL Average time:       557 Microseconds





The test results are a close tie, both ADO.Net and LINQ-to-SQL perform more or less the same, LINQ-to-SQL performs marginally better than ADO.Net when it comes to UPDATE operations. 

The code used to perform the test is as follows


ADO.Net

SqlConnection objConn;
SqlCommand objCmd;
Stopwatch timer;
string strQuery = string.Empty;

timer = new Stopwatch();
timer.Start();

string strConn = ConfigurationManager.ConnectionStrings["EmployeesConnectionString"].ToString();
objConn = new SqlConnection(strConn);
strQuery = "UPDATE Employee SET Name ='Tom',DOB='11/11/1967',DOJ='05/01/2009',Phone='123-123-1234',Email='tom@abcsoftware.com',DepartmentID='1',Salery='6000' WHERE ID = 1";
objCmd = new SqlCommand(strQuery, objConn);
objConn.Open();
objCmd.ExecuteNonQuery();
objConn.Close();
timer.Stop();

lblExecutionTime.Text = "Execution Time (Micro Seconds):" + (1e6 * timer.ElapsedTicks / (double)Stopwatch.Frequency).ToString();


LINQ to SQL

EmployeeClassesDataContext dbContext = new EmployeeClassesDataContext();

Stopwatch timer;
Employee objEmp = (Employee)(from e in dbContext.Employees where e.ID.Equals(1) select e).First();

timer = new Stopwatch();
timer.Start();

objEmp.Name = "Robert";
objEmp.DOB = "10/07/1973";
objEmp.DOJ = "05/01/2009";
objEmp.Phone = "111-222-3333";
objEmp.Email = "robert@abcsoftware.com";
objEmp.DepartmentID = 4;
objEmp.Salery = 5500;

dbContext.SubmitChanges();

timer.Stop();
lblExecutionTime.Text = "Execution Time (Micro Seconds):" + (1e6 * timer.ElapsedTicks / (double)Stopwatch.Frequency).ToString();



Search Flipkart Products:
Flipkart.com

No comments: