Problem with GetTickCount

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi

We're having some timing issues with one of our longer running software
programs.
I am trying to measure how many times my computer can loop through before
one millisecond has passed by and the result is ALWAYS different by a lot.
Almost like it's always a random number.

I'm using VB6.

Dim i As Long
Dim initial_count As Long

i = 0
initial_count = GetTickCount()

Do While GetTickCount() - initial_count < 1
i = i + 1
Loop

MsgBox "The number of loops in 1 millisecond equals " & i

would anyone have any idea why I get a different result everytime?
Thank you in advance

Private Declare Function GetTickCount Lib "kernel32" () As Long
 
This might help.

Dim i As Long
Dim initial_count As Long
Dim end_count As Long
Dim total As Long
Dim j As Long

initial_count = GetTickCount()

For i = 1 To 10000000

j = j + 1

Next

end_count = GetTickCount()
total = 10000000 / (end_count - initial_count)

MsgBox "The number of loops in 1 millisecond equals " & total
 
farsad said:
Hi

We're having some timing issues with one of our longer running software
programs.
I am trying to measure how many times my computer can loop through before
one millisecond has passed by and the result is ALWAYS different by a lot.
Almost like it's always a random number.

I'm using VB6.

Dim i As Long
Dim initial_count As Long

i = 0
initial_count = GetTickCount()

Do While GetTickCount() - initial_count < 1
i = i + 1
Loop

MsgBox "The number of loops in 1 millisecond equals " & i

would anyone have any idea why I get a different result everytime?
Thank you in advance

Private Declare Function GetTickCount Lib "kernel32" () As Long

I don't believe that you'll be able to use GetTickCount in this manner...
The resolution is not precise enough. According to the MSDN documentation
it's resolution is limited to the system timer - which can be obtained by
calling the GetSystemTimeAdjustment function.

If you need 1 ms resolution, then you should be using one of the high
performace timer functions... In particular you should look at the
QueryPerformanceCounter and QueryPerformanceFrequency, or you can look at
the multi-media timer functions.

By the way, this group is really a vb.net group. VB6 and earlier questions
should really be directed to microsoft.public.vb.* groups...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Back
Top