How long a particular piece of code took to execute?

The Stopwatch class under the System.Diagnostics namespace is the key. The Stopwatch class makes it easy to use the high resolution timer in your code.

        // Create new stopwatch
 Stopwatch stopwatch = new Stopwatch();
 // Begin timing
 // Do something
        // Code Here
 // Stop timing
 // Write result
 Console.WriteLine("Time elapsed: {0}",stopwatch.Elapsed);

No comments:

Post a Comment