Any tool that says how long each method takes to run?

c#, optimization, profiling

Solution

The System.Diagnostics namespace offers a helpful class called Stopwatch, which can be used to time parts of your code (think of it as a "poor man's profiler").

This is how you would use it:

Stopwatch stopwatch = new Stopwatch();
stopwatch.Start(); // Start timing

// This is what we want to time
DoSomethingWeSuspectIsSlow();

stopwatch.Stop();
Console.WriteLine("It took {0} ms.", stopwatch.ElapsedMilliseconds);

Problem

some parts of my program are way slow. and I was wondering if there is tool that i can use and for example it can tell me ok running methodA() took 100ms , etc ...or so useful info similar to that.

Original source

Related problems