You can use the Stopwatch
class to measure the duration of your request (or any other code).
Stopwatch sw = Stopwatch.StartNew(); var result = query.ToList(); TimeSpan elapsed = sw.Elapsed; Console.WriteLine("Query took: " + elapsed);
For LINQ queries, remember that they are evaluated only on demand using deferred execution. Thus, you probably want to force them to be enumerated (using, for example, ToList
) to get a true measure of the duration of their execution.
source share