DateTime.Now.Ticks vs QueryPerformanceCounter

  • Thread starter Thread starter Peter
  • Start date Start date
P

Peter

Hi

I am using a "Timing" class which performs timing measurements - and
returns "tick" values to me.

The tick values are however wildly different from DateTime.Now.Ticks,
and I have found out that this is due to the fact that the class is
using a high resolution windows' timer (QueryPerformanceCounter) behind
the scenes - accessible from c# by importing kernel.dll.

Is there any way of comparing the tick values (in a meaningful way)
from DateTime.Now.Ticks and QueryPerformanceCounter? Or do I also need
to use QueryPerformanceCounter in my code if I wish to make a
comparison with the values I receive from the Timing class?


Thanks,
Peter
 
Peter,

On a computer with a Windows OS the timing will never be accurate as there
are other processes runing meanwhile.

That is why when you do some test should perform them moretimes and if
possible at different times.

Cor
 
Cor said:
On a computer with a Windows OS the timing will never be accurate as
there are other processes runing meanwhile.

That is why when you do some test should perform them moretimes and
if possible at different times.

Yes, thanks. But in my problem domain the _exact_ values of the "ticks"
are not really important. My problem lies in comparing the "tick"
values I get from the Timing class I use and the "tick" values I get
from DateTime.Now.Ticks.

Of course, I can just use QueryPerformanceCounter too in my code... but
that would mean changes for me :-P

But in general, I guess, if I get a "tick" count from a class I should
only use "tick" counts from that class, to ensure they are comparable -
as they could be generated in any manner or ways.

/Peter
 
Peter said:
I am using a "Timing" class which performs timing measurements - and
returns "tick" values to me.

I suggest you use the System.Diagnostics.Stopwatch class which is in
..NET 2.0 for precisely this purpose.
 
Peter,

See the answer from Jon, maybe I should have added it, I now see that you
are not using that.

Sorry.

Cor
 
Jon said:
I suggest you use the System.Diagnostics.Stopwatch class which is in
.NET 2.0 for precisely this purpose.

The Stopwatch class seems very useful, and is used for timing from a
"start" to a "stop" time and for obtaining tick timestamps.

I had actually seen this class, but thought it was just for timing
elapsed time - I didn't see that it could also simply supply the
current system tick count.

It seems that the tick count delivered by Stopwatch is the same as that
supplied by QueryPerformanceCounter, so should be compatible with the
tick counts supplied to me by the "Timing" class I am using. (And I do
have access to the Timing class's source code so I guess I could alter
that if I wanted to too).

Thanks,
Peter
 
Back
Top