Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to calculate the execution time of a method in C# with attributes?

Is there an C# attribute (for method) to calculate the time of execution of this method? Is there another way?

like image 764
Bastien Vandamme Avatar asked May 13 '11 13:05

Bastien Vandamme


2 Answers

You can use Aspect Oriented programming to do this. Look at this example from PostSharp: http://www.sharpcrafters.com/solutions/performance

The trick here is to define behavior that will be injected into your code at compile time. One use case is to add timing to methods like you need.

like image 163
Rune Grimstad Avatar answered Sep 27 '22 03:09

Rune Grimstad


there is other way: you could use VS Profiler to check how many times and how long particuler method is executed.

or you could 3rd party library which uses Attributes for profiling the performance, see this related topic What Are Some Good .NET Profilers?

like image 33
Bek Raupov Avatar answered Sep 27 '22 03:09

Bek Raupov