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
measures only processors time kept by process
if process is keeping multiple processors busy, the time of each processor will be added
TimeSpan begin = Process.GetCurrentProcess().TotalProcessorTime;
...
TimeSpan end = Process.GetCurrentProcess().TotalProcessorTime;
Console.WriteLine("Execution time: " + (end - begin).TotalMilliseconds + " ms.");
References