Table of Contents

Execution time

DateTime.UtcNow

DateTime begin = DateTime.UtcNow;
...
DateTime end = DateTime.UtcNow;
Console.WriteLine("Execution time: " + (end-begin).TotalMilliseconds + " ms.");

Stopwatch

Stopwatch watch = new Stopwatch();
watch.Start();
...
watch.Stop();
Console.WriteLine("Execution time: " + watch.Elapsed.TotalMilliseconds + " ms.");

Process.TotalProcessorTime

TimeSpan begin = Process.GetCurrentProcess().TotalProcessorTime;
...
TimeSpan end = Process.GetCurrentProcess().TotalProcessorTime;
Console.WriteLine("Execution time: " + (end - begin).TotalMilliseconds + " ms.");

References