I need to measure a function’s performance. What is the best way to do this?

Hello Will

I have a bottleneck in some part of my .net programming code that I need to measure the time it takes to run as accurately as possible. What is the best way to measure the performance?

Sheri from Gaithersburg

One thought on “I need to measure a function’s performance. What is the best way to do this?

  1. Hello Sheri

    The best way to measure performance in .net programming is to use Stopwatch from System.Diagnostics

    Stopwatch sw = Stopwatch.StartNew();

    // Execute your work

    sw.Stop();

    Console.WriteLine("Time taken: {0}ms", sw.Elapsed.TotalMilliseconds);

    Stopwatch automatically checks for the existence of high-precision timers.
    Will 

Comments are closed.