Loading ...

Calculating the execution time of each functions/methods

Who is online?  0 guests and 0 members
home  »  forums   »  asp.net topics   »  visual studio   » Calculating the execution time of each functions/methods

Calculating the execution time of each functions/methods

Posts under the topic: Calculating the execution time of each functions/methods

Posted: 5/24/2010

Lurker 52  points  Lurker
  • Joined on: 5/24/2010
  • Posts: 10

How can we calculate the execution time of each functions/methods in any project so that we should know which funtion is take so much time and we need to work on that?

Is there any prebuild method or property so that we can calculate the execution time?


Posted: 5/24/2010

Professional 8495  points  Professional
  • Joined on: 5/3/2010
  • Posts: 389
  Answered

If you have knowledge of Data Structures  (which is usually course in Computer Sciences field), you may have imagination of how to calculate execution time.

Anyway, you can try something like this:

1. Create DateTime dtStart = DateTime.Now;

2. Call the function you want to test

3. After function call line, add DateTime dtEnd = DateTime.Now

At last, create TimeSpan ts = dtEnd - dtStart

Example:

DateTime dtStart = DateTime.Now;

functionName(params);

DateTime dtEnd = DateTime.Now;

TimeSpan ts = dtEnd - dtStart;

// you have the  time in the ts value so play with it :).

Regards,
Hajan



Posted: 5/25/2010

Lurker 52  points  Lurker
  • Joined on: 5/24/2010
  • Posts: 10

Thankx for the suggestion for this logic.


Posted: 5/26/2010

Guru 16518  points  Guru
  • Joined on: 4/19/2009
  • Posts: 483
  Answered

Go with profilers. There are many, I will suggest to go with ANTS Performance Profiler™ and dotTrace


tags profiler
Page 1 of 1 (4 items)