DateTime.now.ticks question

  • Thread starter Thread starter ed via DotNetMonster.com
  • Start date Start date
E

ed via DotNetMonster.com

Hi All:

My program is working nicely, thank you Paul Tobey and Chris Tacke for
helping me in my previous posts.

I have a quick question about the ticks. I am trying to count how many ticks
(if possible) it takes to execute a piece of routine. I have something
simillar like the following in my program:

dtBegin as long
dtEnd as long
dtDiff as long

routine entry
dtBegin = DateTime.now.ticks
routine runs
dtEnd = DateTime.now.ticks
dtDiff = dtEnd - dtBegin
program counter returns

somehow, the dtDiff is always 0. <- so um, my routine is running at less than
100 nano-seconds?
Is there some way to effectively measure the execution speed with relatively
easy implementation?
by the way, I am trying to measure my routine in compact framework.

Thanks for reading, any help is appreciated.
 
System.DateTime only returns time with a resolution of 1 second. For
millisecond timings you should use Environment.TickCount (and be aware of
potential wrapping issues). For even higher resolution (if supported) you
can P/Invoke down to QueryPerformanceCounter etc. If you go down that route,
I'd advise you to look at the source code for
OpenNETCF.Diagnostics.Stopwatch - vault.netcf.tv (username guest, password
guest)

Peter
 
Thanks Peter, that was great help.
System.DateTime only returns time with a resolution of 1 second. For
millisecond timings you should use Environment.TickCount (and be aware of
potential wrapping issues). For even higher resolution (if supported) you
can P/Invoke down to QueryPerformanceCounter etc. If you go down that route,
I'd advise you to look at the source code for
OpenNETCF.Diagnostics.Stopwatch - vault.netcf.tv (username guest, password
guest)

Peter
[quoted text clipped - 26 lines]
Thanks for reading, any help is appreciated.
 
Back
Top