I would like to be able to calculate the amount of time a number of functions take to execute. I was thinking about using some type of stopwatch class. I can call start/stop before and after each function call, however that seems horribly ugly to me. Is there a way to do this without a stopwatch class? Can something in the Reflections class help with this?
Thanks in advance for you input.
I think u must try the PostSharp way http://www.postsharp.org/
Changing the code in the sample for this one:
public class ProfileMethodsAttribute : OnMethodBoundaryAspect
{
public override void OnEntry( MethodExecutionEventArgs eventArgs)
{ eventArgs.MethodExecutionTag = Stopwatch.StartNew(); }
public override void OnExit( MethodExecutionEventArgs eventArgs)
{
// Here u can get the time
Console.WriteLine(((Stopwatch)eventArgs.MethodExecutionTag).ElapsedMilliseconds);
}
}
You can get the time off any method
I recommend the sponsor of the performance tag ... Red Gate Ants. You can get a demo that will run your app and give you performance information for every line and every method that your app hits while it is being profiled.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With