LINQ - Get total query execution time

I would like to know if I can get the query "search results"? For example, how Google has time under each request - this is the time it takes to complete the search .

How is this achievable? I have not tried anything (hence no code) because, well, I'm not sure where to start.

LINQPad has a built-in function, but I would like to get something similar to the internal mvc application I'm working on.

thanks

+4
source share
2 answers

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.

+9
source

You can use the System.Diagnostics.Stopwatch object, start it when the page starts rendering and stops it at the end.

0
source

Source: https://habr.com/ru/post/1415895/


All Articles