By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,995 Members | 1,088 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,995 IT Pros & Developers. It's quick & easy.

Calculate processing time.

P: n/a
Hello,

I do:

Debug.WriteLine("A: " & DateTime.Now.Ticks.ToString)
REM Calculate a bunch of stuff. Some loops and math functions.
Debug.WriteLine("B: " & DateTime.Now.Ticks.ToString)

but both A and B have the exact the same value. Is this method incorrect?
When I make the function wait for 1 millisecond, A en B differ. Is there
another way to calculate the processing time? Without looping the stuff a
100 times and then devide the result by 100.

Thanks.
Dec 12 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
>
Debug.WriteLine("A: " & DateTime.Now.Ticks.ToString)
REM Calculate a bunch of stuff. Some loops and math functions.
Debug.WriteLine("B: " & DateTime.Now.Ticks.ToString)

but both A and B have the exact the same value. Is this method incorrect?
When I make the function wait for 1 millisecond, A en B differ. Is there
another way to calculate the processing time? Without looping the stuff a
100 times and then devide the result by 100.


I would prefer doing it 100 or even more times, to make sure you get an
accurate timing.

The first time you run a routine the CLR might do some optimizing that
actually makes it run slower the first few times.

/Søren Reinke
Dec 12 '05 #2

P: n/a
"Qwert" <no**@nosp.com> schrieb
Hello,

I do:

Debug.WriteLine("A: " & DateTime.Now.Ticks.ToString)
REM Calculate a bunch of stuff. Some loops and math functions.
Debug.WriteLine("B: " & DateTime.Now.Ticks.ToString)

but both A and B have the exact the same value. Is this method
incorrect? When I make the function wait for 1 millisecond, A en B
differ. Is there another way to calculate the processing time?
Without looping the stuff a 100 times and then devide the result by
100.

In addition to Søren, the resolution of DateTime.Now is too low to measure
things. Use Environment.Tickcount (returns milliseconds) instead or a high
performance counter (in VB 2005, you can use System.Diagnostics.Stopwatch)

See also:
http://groups.google.com/group/micro...7a1a5c8d980072

(especially post #4ff ;-)

Armin

Dec 12 '05 #3

P: n/a
"Qwert" <no**@nosp.com> schrieb:
Debug.WriteLine("A: " & DateTime.Now.Ticks.ToString)
REM Calculate a bunch of stuff. Some loops and math functions.
Debug.WriteLine("B: " & DateTime.Now.Ticks.ToString)

but both A and B have the exact the same value. Is this method incorrect?


You may want to use this timer:

<URL:http://www.mentalis.org/soft/class.qpx?id=8>

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Dec 12 '05 #4

P: n/a
Great, thanks all.

That 'QueryPerformanceCounter' and 'QueryPerformanceFrequency' code of
mentalis did the trick. None of the .NET functionality I could find was
precise enough (fastest time was 0,0003 seconds).

Don't have VB2005 yet, so I couldn't try "in VB 2005, you can use
System.Diagnostics.Stopwatch". I did try:

Dim objProcessorTime As New System.Diagnostics.PerformanceCounter()
objProcessorTime.CategoryName = "Processor"
objProcessorTime.CounterName = "% Processor Time"
objProcessorTime.InstanceName = "_Total"

but wasn't precise enough.

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> schreef in bericht
news:OI**************@tk2msftngp13.phx.gbl...
"Qwert" <no**@nosp.com> schrieb:
Debug.WriteLine("A: " & DateTime.Now.Ticks.ToString)
REM Calculate a bunch of stuff. Some loops and math functions.
Debug.WriteLine("B: " & DateTime.Now.Ticks.ToString)

but both A and B have the exact the same value. Is this method incorrect?


You may want to use this timer:

<URL:http://www.mentalis.org/soft/class.qpx?id=8>

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Dec 12 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.