I would like to know if it is possible to get a query 'search results' time? Like how google has a time under each query - this is the time it took to complete the search.
How is this achievable? I haven't attempted anything (hence no code) because, well, I'm not sure where to start.
LINQPad has this feature built in, but I'd like to get something similar going on an internal mvc app I'm working on.
Thanks
You could use the Stopwatch
class to measure the duration of the execution of your query (or any other code).
Stopwatch sw = Stopwatch.StartNew();
var result = query.ToList();
TimeSpan elapsed = sw.Elapsed;
Console.WriteLine("Query took: " + elapsed);
In the case of LINQ queries, don’t forget that these are only evaluated on demand using deferred execution. Thus, you would probably want to force their enumeration (using, for example, ToList
) in order to get a true measure of their execution’s duration.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With