perfomrance monitoring

  • Thread starter Thread starter MFRASER
  • Start date Start date
M

MFRASER

What is the best way to test how long a method takes to load?

I am currently doing the following
System.DateTime aStartNow = DateTime.Now;

// do something

System.DateTime aEndNow= DateTime.Now;

System.TimeSpan TimeDiff = aEndNow- aStartNow ;

//Log TimeSpan
 
MFRASER said:
What is the best way to test how long a method takes to load?

I am currently doing the following
System.DateTime aStartNow = DateTime.Now;

// do something

System.DateTime aEndNow= DateTime.Now;

System.TimeSpan TimeDiff = aEndNow- aStartNow ;

//Log TimeSpan

It depends on the time resolution that you are after. A rough rule of thumb
for general timing is a resolution that is 1/2 the expected duration. Typical
Windows timers/time has a resolution of around 55 ms (1/20th of a second). So,
if your method takes .1 seconds or longer, std timer accuracy would probabaly
be sufficient.

If you are interested in high-precision timing, you will have to use low level
(hardware) performance timers, which I doubt are wrapped by the .Net
framework. Look into Win32 QueryPerformanceCounter() and related and see what
you can turn up.
 
Back
Top