Just curious as to what people think is the best way to calculate how long a search takes and then display time to user.
I am using DateTime with Timespan and also Stopwatch sw = new Stopwatch.
I think using Stopwatch is cleaner code compared to DateTime with timespan.
So I'm just curious as to what professional programmers use.
i.e
Stopwatch WebSearchTime = new Stopwatch();
WebSearchTime.Start();
code to run
WebSearchTime.Stop();
double WST = WebSearchTime.Elapsed.Seconds + (WebSearchTime.Elapsed.Milliseconds / 1000.0);
Thanks
George
Stopwatch is the proper and more accurate way to determine time of execution, than DateTime.Now with DateTime calculation.
Stopwatch Class
The Stopwatch measures elapsed time by counting timer ticks in the underlying timer mechanism. If the installed hardware and operating system support a high-resolution performance counter, then the Stopwatch class uses that counter to measure elapsed time. Otherwise, the Stopwatch class uses the system timer to measure elapsed time. Use the Frequency and IsHighResolution fields to determine the precision and resolution of the Stopwatch timing implementation.
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