How to measure code performance in c# by measuring execution time


Back to learning
Created: 08/01/2016



How to measure code performance in c# by measuring execution time.




using System.Diagnostics;


Stopwatch sw = new Stopwatch();
sw.Start();

// ... Your code to test goes here...

sw.Stop();

Console.WriteLine("Elapsed={0}",sw.Elapsed); // Print the result.