Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 663869
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T23:32:12+00:00 2026-05-13T23:32:12+00:00

I am working on tool to optimize linq to sql queries. Basically it intercepts

  • 0

I am working on tool to optimize linq to sql queries. Basically it intercepts the linq execution pipeline and makes some optimizations like for example removing a redundant join from a query. Of course, there is an overhead in the execution time before the query gets executed in the dbms, but then, the query should be processed faster. I don’t want to use a sql profiler because I know that the generated query will be perform better in the dbms than the original one, I am looking for a correct way of measuring the global time between the creation of the query in linq and the end of its execution. Currently, I am using the Stopwatch class and my code looks something like this:

var sw = new Stopwatch();
sw.Start();
const int amount = 100;
for (var i = 0; i < amount; i++)
{
   ExecuteNonOptimizedQuery();
}
sw.Stop();
Console.Writeline("Executing the query {2} times took: {0}ms. On average, each query took: {1}ms", sw.ElapsedMilliseconds, sw.ElapsedMilliseconds / amount, amount);

Basically the ExecutenNonOptimizedQuery() method creates a new DataContext, creates a query and then iterates over the results.

I did this for both versions of the query, the normal one and the optimized one. I took the idea from this post from Frans Bouma.

Is there any other approach/considerations I should take?

Thanks in advance!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T23:32:12+00:00Added an answer on May 13, 2026 at 11:32 pm

    You could Run under a profiler. But an instrumented build will impact the performance of the code, possibly distorting the result (with a large part of the total execution time in SQL Server, this is very likely). A sampling profiler might help. (The Visual Studio Team System profiler can do both.)

    For an isolated test to compare to approaches using Stopwatch is generally the preferred approach. You can remove the time show in SQL Profiler from the stopwatch time to get the time in client code (including your post-processing).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on a tool that will perform some simple transformations on programs (like
I'm very interesting in inexpensive (better free) SQL query tool for working with multiple
I'm looking for an Oracle database management tool like sql server management studio. I've
I've been working on a tool to transcribe recordings of speech with Javascript. Basically
I am working on javascript tool for a client site at the moment, basically
I am working on a tool in C to count some incoming/outgoing bits, I
I am working on a tool a little like xARP. It simply detects changes
I'm working on a tool for visualizing objects in Java. This tool provides some
recently i was working on a tool, where user makes changes on the interface
I'm trying to get bootstrap tool tips working in a simple example. Here's a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.