0

I have application with more than 500 classes under on each DLL. By this way application includes 7 to 10 DLLs.

For optimization purpose, I want to know the time taken for each method and sub-methods for a particular process.

To achieve this, I add 2 lines of code at beginning and end of each method, which add the method name and time of execution to log file. Once I found the long running method and optimize it, remove those lines.

Is there any automation available for this process? Like by enabling any Boolean settings framework will write log file with method name and execution time of the same. :)

(or) Is there any other way easy way to achieve the above? :(

vaduganathan
  • 141
  • 1
  • 1
  • 11
  • 1
    Don't waste your time. Try an evaluation version of something like [RedGate's ANTS Profiler](http://www.red-gate.com/products/dotnet-development/ants-performance-profiler/), or many other .NET profilers out there (like [dotTrace](https://www.jetbrains.com/profiler/)). They can tell you more accurately, and granular, where any bottlenecks may be in your codepaths. If they suite your needs, consider purchasing a named licence. Yeah it costs money, but saves so much time long term. – Jason Evans May 28 '15 at 13:17
  • possible duplicate of [What Are Some Good .NET Profilers?](http://stackoverflow.com/questions/3927/what-are-some-good-net-profilers) – Scott Chamberlain May 28 '15 at 13:17
  • Perhaps you should review existing performance profilers for .NET. See the book [Pro .NET Permormance](http://www.apress.com/9781430244585). The first part contains an info about existing tools. – Mark Shevchenko May 28 '15 at 13:23

1 Answers1

1

You should use a profiler instead of reinventing the wheel. Also, your timing probably would be off, since it is very hard to get the time measurement good. This might lead to you diagnosing the wrong piece of code. Your method is also very time consuming and error prone.

A few profilers I have worked with:

If you had like to see some 'real life action' usage on ANTS, see this post where I included some diagrams from ANTS.

Community
  • 1
  • 1
Patrick Hofman
  • 153,850
  • 22
  • 249
  • 325