TimeSpan, Ticks

  • Thread starter Thread starter Jon Skeet [C# MVP]
  • Start date Start date
J

Jon Skeet [C# MVP]

Jeroen CEuppens said:
Hi, I want to measure a time (in ticks) between a couple of operations, with
these code:

long voor = DateTime.Now.TimeOfDay.Ticks;

bmp1 = new Bitmap(@"\Network\im\ImageWeftIllum.bmp");

bmp2 = new Bitmap(@"\Network\im\ImageWarpIllum.bmp");

g.DrawImage( bmp1, 0, 0 );

g.DrawImage( bmp2, 1, 1 );

long na = DateTime.Now.TimeOfDay.Ticks;;

na=na-voor;

textBoxTijd.Text=na.ToString()+" ticks";

Firstly, I'd just use:

DateTime voor = DateTime.Now;

....

DateTime na = DateTime.Now;

TimeSpan diff = na-voor;

and then use the results of that. However...
The textBoxTijd only gives something like this: 2000 000 ticks or 3000 000
ticks, but never something like 3333 325, what's the problem? I also put
more operations between the measuring, but always some stuff like that: 2000
000 33 000 000, help me pleae
I debug on a Win CE 4.2

The Pocket PC timer is very coarse - ie it doesn't update very often. I
suspect you would still see multiples of ticks even on a desktop
system, but with a Pocket PC it'll be more pronounced.
 
If you need high precision timing i recommend you use the
QueryPerformanceCounter and QueryPerformanceFrequency that is in
kernel32.dll

Just wrap these (there is a KB article on MSDN for this) and call them.
 
Hi, I want to measure a time (in ticks) between a couple of operations, with
these code:

long voor = DateTime.Now.TimeOfDay.Ticks;

bmp1 = new Bitmap(@"\Network\im\ImageWeftIllum.bmp");

bmp2 = new Bitmap(@"\Network\im\ImageWarpIllum.bmp");

g.DrawImage( bmp1, 0, 0 );

g.DrawImage( bmp2, 1, 1 );

long na = DateTime.Now.TimeOfDay.Ticks;;

na=na-voor;

textBoxTijd.Text=na.ToString()+" ticks";



The textBoxTijd only gives something like this: 2000 000 ticks or 3000 000
ticks, but never something like 3333 325, what's the problem? I also put
more operations between the measuring, but always some stuff like that: 2000
000 33 000 000, help me pleae

I debug on a Win CE 4.2

THX
 
Jeroen CEuppens said:
I hope the PerformanceCounter works to counts time for operations or do you
know any better way to counts time?

I don't, I'm afraid - I don't know whether that PerformanceCounter
exists on Pocket PC. I suggest you ask again in the compactframework
newsgroup - you may well get better answers.
 
Thx for info,

The Pocket PC timer is very coarse , idd, i check it, windows xp give me 33
ms or 33,750, but CE don't

I use this also, same result, nog good vision of the milliseconds :(
DateTime voor = DateTime.Now;
...

DateTime na = DateTime.Now;

TimeSpan diff = na-voor;


I hope the PerformanceCounter works to counts time for operations or do you
know any better way to counts time?

Thx
 
Back
Top