473,387 Members | 1,892 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Is LINQ consumes double the time of Traditional Data Connection?

Today, after watching the presentation by Amanda Silver at
http://channel9.msdn.com/Showpost.aspx?postid=335058 , from Channel 9,
started exploring the LINQ features. Surprisingly, few facts unearthed to
prove that LINQ is slower, much to double the time consumed by the usage of
traditional Data Adapter. Correct me if you find these facts can be proved
fault

HW Scenario :
----------------------------------------------------------------------------
System OS - XP Prof with SP2
System Processor - AMD 3000+ with 2GHz
RAM - 1 GB
DB Server - LocalHost on SQL Server 2005
Implemented with Orcas Beta 2
----------------------------------------------------------------------------

Source Code copied from Amanda's presentation

Code Snippet for LINQ
----------------------------------------------------------------------------
Dim t1, t2 As Double

t1 = Date.Now.TimeOfDay.TotalMilliseconds

Dim db As New exLinqDataContext(My.Settings.NorthwindConnectionS tring)

Dim query = From cust In db.Customers _

Join sup In db.Suppliers _

On cust.City Equals sup.City _

Select cust.CompanyName, sup.ContactName, cust.City

Me.DataGridView1.DataSource = query

t2 = Date.Now.TimeOfDay.TotalMilliseconds

Dim diffT As Double

diffT = t2 - t1

MessageBox.Show(diffT)
----------------------------------------------------------------------------
Source Code using Traditional Data Adapter
----------------------------------------------------------------------------
Dim t1, t2 As Double

t1 = Date.Now.TimeOfDay.TotalMilliseconds

Dim cn As New SqlClient.SqlConnection("Data Source=localhost;Initial
Catalog=Northwind;Integrated Security=True")

Dim da As New SqlClient.SqlDataAdapter("Select
C.CompanyName,S.ContactName,C.City from Customers C,Suppliers S Where C.City
= S.City", cn)

Dim DS As New DataSet

da.Fill(DS)

GV.DataSource = DS.Tables(0)

t2 = Date.Now.TimeOfDay.TotalMilliseconds

Dim diffT As Double

diffT = t2 - t1

MessageBox.Show(diffT)
----------------------------------------------------------------------------

For your attention here comes the result for the first execution time of
each method

-------------------
LINQ DataAdapter
-------------------
171.875 93.750
171.875 93.750
156.250 78.125
156.250 78.125
156.250 78.125
-------------------

Can some one help me to understand to interpret the results and how LINQ is
advantageous than the tradtional way of using Data Adapter with Data
Connections

--
Every thing is perfect, as long as you share!!!

Don''t forget to rate the post
Sep 3 '07 #1
7 1326
Chakravarthy <ds******@india.comwrote:

<snip>
Can some one help me to understand to interpret the results and how LINQ is
advantageous than the tradtional way of using Data Adapter with Data
Connections
Have you looked at the SQL query being used? Those figures are pretty
odd... normally LINQ should be "about" as fast as traditional methods,
so long as the query is equivalent.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Sep 3 '07 #2
Jon,

Yes, what you said is correct from the point of statements given by the
representatives as well as by the company, Microsoft's official barriers. But
unfortunately, the figures doesn't lie. Am really surprised to see such kind
of figures specially using the latest framework version.

Secondly, i guess there is nothing wrong in the SQL Query. Correct me if am
found fault.

Anyhow, thanks for replying.
--
Every thing is perfect, as long as you share!!!

Don''t forget to rate the post
"Jon Skeet [C# MVP]" wrote:
Chakravarthy <ds******@india.comwrote:

<snip>
Can some one help me to understand to interpret the results and how LINQ is
advantageous than the tradtional way of using Data Adapter with Data
Connections

Have you looked at the SQL query being used? Those figures are pretty
odd... normally LINQ should be "about" as fast as traditional methods,
so long as the query is equivalent.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Sep 4 '07 #3
Chakravarthy <ds******@india.comwrote:
Yes, what you said is correct from the point of statements given by the
representatives as well as by the company, Microsoft's official barriers. But
unfortunately, the figures doesn't lie.
Benchmarks can very, very easily be wrong. Benchmarking is really quite
tricky to get right.
Am really surprised to see such kind
of figures specially using the latest framework version.

Secondly, i guess there is nothing wrong in the SQL Query. Correct me if am
found fault.
You haven't told us what the query generated by LINQ is. That's what I
was asking before.

If you could produce a short but *complete* program, we could test it
for ourselves, of course.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Sep 4 '07 #4
Chakravarthy <ds******@india.comwrote:

<snip>

For a more detailed analysis of LINQ performance see Rico's blog:

http://blogs.msdn.com/ricom/archive/...q-linq-to-sql-
performance-part-1.aspx

http://blogs.msdn.com/ricom/archive/...q-linq-to-sql-
performance-part-2.aspx

http://blogs.msdn.com/ricom/archive/...q-linq-to-sql-
performance-part-3.aspx

http://blogs.msdn.com/ricom/archive/...q-linq-to-sql-
performance-part-4.aspx

http://blogs.msdn.com/ricom/archive/...q-linq-to-sql-
performance-part-5.aspx

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Sep 4 '07 #5
Jon,

Thanks a lot for your reply. Please follow the steps to reproduce the
*complete* program

Step1: Create a windows Application
Step2: Drag a GridView on the windows form
Step3: As mentioned by Amanda, copy the mentioned code onto the Click event
of GridView

Finally, you have the both code snippets. I've taken 2 different windows
applications to run tme individually.

Hope am clear at this, ping me back if am missing some thing.

"Jon Skeet [C# MVP]" <sk***@pobox.comwrote in message
news:MP*********************@msnews.microsoft.com. ..
Chakravarthy <ds******@india.comwrote:
>Yes, what you said is correct from the point of statements given by the
representatives as well as by the company, Microsoft's official barriers.
But
unfortunately, the figures doesn't lie.

Benchmarks can very, very easily be wrong. Benchmarking is really quite
tricky to get right.
>Am really surprised to see such kind
of figures specially using the latest framework version.

Secondly, i guess there is nothing wrong in the SQL Query. Correct me if
am
found fault.

You haven't told us what the query generated by LINQ is. That's what I
was asking before.

If you could produce a short but *complete* program, we could test it
for ourselves, of course.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Sep 4 '07 #6
On Sep 4, 2:58 pm, "DSK Chakravarthy" <dskch...@msn.comwrote:
Thanks a lot for your reply. Please follow the steps to reproduce the
*complete* program

Step1: Create a windows Application
Step2: Drag a GridView on the windows form
Step3: As mentioned by Amanda, copy the mentioned code onto the Click event
of GridView

Finally, you have the both code snippets. I've taken 2 different windows
applications to run tme individually.

Hope am clear at this, ping me back if am missing some thing.
It would be far better if you'd just post some code we can compile and
run.

See http://pobox.com/~skeet/csharp/complete.html

Jon

Sep 4 '07 #7
Chakravarthy <ds******@india.comwrote:

<snip>
For your attention here comes the result for the first execution time of
each method
I've only just spotted the word "first" in here.

What about the next time you execute the query? On my box, that's much,
much faster. This makes sense - not only has LINQ got to connect to the
database (like the DataAdapter does) but it's also got to build an
assembly. That assembly can be reused for subsequent queries, however.
Try measuring the subsequent executions of the same query and I'm sure
you'll see a big difference.

How much do you care about losing a tenth of a second or so of
performance *once* (per run) compared with the *huge* benefit in
development effort that LINQ will bring?

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Sep 4 '07 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

28
by: Marc Gravell | last post by:
In Linq, you can apparently get a meaningful body from and expression's .ToString(); random question - does anybody know if linq also includes a parser? It just seemed it might be a handy way to...
6
by: Dmitry Perets | last post by:
Hello, I am trying to work with MS SQL Server 7 from the release version of Visual Studio 2008 + LINQ to SQL. And the problem is that the LINQ to SQL designer doesn't accept my tables saying...
7
by: Andy B | last post by:
Just wondering why linq is more useful than datasets? The stuff I do doesn't seem to be too complicated to use linq with it. If I did use linq with it now, I would be doing almost the exact same...
4
by: =?Utf-8?B?RXJpYyBGYWxza2Vu?= | last post by:
We’re storing our main entity in an insert only table which stores the history of past revisions, but we’re facing problems with storing this history as LINQ will only update the entity, and...
2
by: =?Utf-8?B?UGFvbG8=?= | last post by:
Learning C# and SQL Server. Just wondered what are the pros and cons of either approach to using SQL Server databases. (It may be 'how long is a piece of string'!) Thanks
1
by: Dean Slindee | last post by:
VS2008, .NetFramework 3.5 SP1: I have built a LINQ data access layer project. When the LINQ data context was built over an existing SQL2005 database, the connection string for that database was...
0
by: bob laughland | last post by:
Hi All, I am using a combination of LINQ to SQL and bulk insert. In the process of performing 'one unit of work' I will be doing things like reading, and deleting records using LINQ to SQL and...
3
by: bob laughland | last post by:
Hi All, I am using a combination of LINQ to SQL and bulk insert. In the process of performing 'one unit of work' I will be doing things like reading, and deleting records using LINQ to SQL and...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.