EF faster than query from management studio? RRS feed

  • General discussion

  • I am conducting performance tests. I created test DB with main table with 3 milion rows and with some tables with about 11 milions to filter by.

    I wrote simple app using Entity Framework 4 to get filtered records. Then I figured out the query used by EF (using SQL Profiler).

    I pasted this query into SQL Management Studio. It took about 8sec to execute.

    However the same query on the same database took only 3sec to execute when my application using EF.

    How is that possible? In my application the data was not only downloaded, but it also was converted for objects, so it should take more time.

    Thank you for help in advance


    Wednesday, January 16, 2013 11:12 AM

All replies

  • Hi,

    Does the time measured in Management Studio takes into account displaying those data unlike the EF code ?

    Please always mark whatever response solved your issue so that the thread is properly marked as "Answered".

    Wednesday, January 16, 2013 11:53 AM
  • That's good question and I don't really know the answer but here's a few things to consider:

    • EF compiles the query when run, if it is called again and the compiler determines it doesn't need to recompile it, then it's faster. (Theory only)
    • SSMS is a big client side SQL Application, who really knows what it does when it sends a query to database, sure we could determine that by running a commuications trace but we still don't know what additional times are included in the client side getting to the point of sending the query across the wire. 
    • SSMS may attempt to optimize the query whereas EF does it differently.  Once optimized I would guess that SSMS would be faster.
    • EF is newer technology, sometimes newer technology is just plain faster.  I remember when WEBBROWSERs first hit the scene. It was clear in a lot of respects that going to the internet was way faster than the older technologies.  The main reason, most likely, is that the older stuff was not optimized for speed.  Rather they were optimized for accuracy back in the day of bad connections with lots of retry logic.  Older code has a lot of legacy stuff in it which keeps things slow.  The older software is the more it has to support. 

    JP Cowboy Coders Unite!

    Wednesday, January 16, 2013 1:18 PM