If you want to write some kind of test code to profile various functions or parts of them, you should use System.Diagnostics.Stopwatch to track elapsed time. Like this:
public void DoSomething(){ Stopwatch stopWatch = new Stopwatch(); stopWatch.Start();
If this is the more general thing you want to do (i.e. find out which parts of the program are slow), then use the profiler as some of the other answers suggest.
source share