Thank you very much for this. One of the things we try to
the accurate time of the call. We don't know what happens
behind their component.
>-----Original Message-----
>Michael <anonymous@discussions.microsoft.com> wrote:
>> I am not sure if this is already a known issue.
>> When I calculate the time elapse for a partular
activity
>> using AverageTimer32 type perfmon counter, should I
use:
>>
>> long t1=DateTime.Now.Ticks;<--1
>> //some activities
>> long t2=DateTime.Now.Ticks;<--2
>> MyAverageTimer32.incrementBy(t2-t1);
>> MyBase.increment();
>>
>> or replace the code in #1, #2 with this
>>
>> QueryPerformanceCounter(ref t1);
>> QueryPerformanceCounter(ref t2);
>>
>> Saw some posts said the first one is not accurate, and
>> some say we should not use the second style,,, any one
>> can provide a anwser?
>
>I personally use the first version - it's more portable
(to Mono etc)
>and doesn't require any extra declarations etc.
>
>Yes, it's less accurate - but I usually reckon that if
you're measuring
>times so small that the loss of accuracy there is
relevant, you're
>leaving yourself open to other things (such as other
processes getting
>timeslices) mucking your results up significantly
anyway. Certainly for
>benchmarking etc, I prefer to time as long a period as
realistically
>possible - for small tests, a minute is a good thing to
aim for,
>although for some types of tests it's unrealistic as
other resources
>(eg memory) will be exhausted before you can run for a
minute.
>
>Anyway, with a period of time like that, the inaccuracy
of DateTime.Now
>really doesn't matter.
>
>Small point - I like to keep my DateTimes as DateTimes:
>
>DateTime start = DateTime.Now;
>// ...
>DateTime end = DateTime.Now;
>TimeSpan timeTaken = end-start;
>
>--
>Jon Skeet - <skeet@pobox.com>
>
http://www.pobox.com/~skeet
>If replying to the group, please do not mail me too
>.