Possible Duplicate:
Profiling a method in C# to know how long does it take to run
I need to check how long does it take to run a method.
For example, I need to know how long does it take to run GetTypes()
method in using System.Reflection
in my project.
foreach (Type t2 in a.GetTypes())
{
Console.WriteLine(t2);
}
The easiest way might be running profiler or insert Stopwatch
all the source files that uses GetTypes(), but I hope I could use hooking the GetTypes() method to start and quit the stop watch before and after running GetTypes() method.
sw = Stopwatch.StartNew();
foreach (Type t2 in a.GetTypes())
{
Console.WriteLine(t2);
}
sw.Stop();
Can I do that with C#/.NET(Mono)? If not, do I have other options than modifying the source code or running the profiler?