A better way is to use the Stopwatch class:
using System.Diagnostics;
// ...
Stopwatch sw = new Stopwatch();
sw.Start();
// ...
sw.Stop();
Console.WriteLine("Elapsed={0}",sw.Elapsed);
More Related Contents:
- Best way to reverse a string
- String vs. StringBuilder
- How slow are .NET exceptions?
- How to get object size in memory? [duplicate]
- Benchmarking small code samples in C#, can this implementation be improved?
- Does C# optimize the concatenation of string literals?
- Is String.Contains() faster than String.IndexOf()?
- LINQ: Not Any vs All Don’t
- What is the real overhead of try/catch in C#?
- Performance of calling delegates vs methods
- When is optimization premature? [closed]
- Why is LINQ .Where(predicate).First() faster than .First(predicate)?
- How do I do logging in C# without using 3rd party libraries? [closed]
- C# / F# Performance comparison
- How does extern work in C#?
- How performant is StackFrame?
- How to force a number to be in a range in C#? [duplicate]
- Performance of Find() vs. FirstOrDefault() [duplicate]
- Does String.GetHashCode consider the full string or only part of it?
- Warm-up when calling methods in C#
- LINQ performance FAQ
- Is it better to execute many sql commands with one connection, or reconnect every time?
- Selenium WebDriver throws Timeout exceptions sporadically
- Why is my C# program faster in a profiler?
- When to use pointers in C#/.NET?
- When to change the Generate Serialization Assembly value?
- Slow SoapHttpClientProtocol constructor
- Does any one know of a faster method to do String.Split()?
- Heap versus Stack allocation implications (.NET)
- Why subsequent direct method call is much faster than the first call?