C # 2.0 Runtime

I would like to be able to calculate the amount of time that a number of functions take to complete. I was thinking about using some type of stopwatch class. I can call start / stop before and after each function call, however this seems terribly ugly to me. Is there a way to do this without a stopwatch class? Can something in the Reflections class help with this?

Thank you in advance for your input.

+5
source share
5 answers

I think u should try the PostSharp method http://www.postsharp.org/

Changing the code in the example for this:

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 disable any way

+3

... Red Gate Ants. , , , , .

+2

, ... , Ants Profiler, ? Red Gate , , /open source .

/ ...

, , .

+1

you can put the stopwatch class in the attribute used to decorate your methods, i.e. for the AOP style. check this

+1
source

There are various timers. System.Timers.Timerwill be one of those. But as the previous answer shows, are you sure that this is the right solution to the problem you are trying to solve?

0
source

All Articles