How to calculate the execution time of c# application. I am having c# windows application in which i need to calculate the execution time and i dont have any idea where i have to proceed this. Can anyone please help me?
use Stopwatch of System.Diagnostics
static void Main(string[] args)
{
Stopwatch stopWatch = new Stopwatch();
stopWatch.Start();
Thread.Sleep(10000);
stopWatch.Stop();
// Get the elapsed time as a TimeSpan value.
TimeSpan ts = stopWatch.Elapsed;
// Format and display the TimeSpan value.
string elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}",
ts.Hours, ts.Minutes, ts.Seconds,
ts.Milliseconds / 10);
Console.WriteLine("RunTime " + elapsedTime);
}
You could, for instance, just use DateTime.Now
before and after your execution and then subtract the milliseconds:
DateTime then = DateTime.Now;
// Your code here
DateTime now = DateTime.Now;
Console.WriteLine(now.Millisecond - then.Millisecond);
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