473,394 Members | 1,737 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Problem with GetTickCount

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


Nov 21 '05 #1
2 6188
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 nasseri" <farsad na*****@discussions.microsoft.com> wrote in message
news:63**********************************@microsof t.com...
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

Nov 21 '05 #2
farsad nasseri wrote:
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...

--
Tom Shelton [MVP]
Nov 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: MaKiT | last post by:
I have a program which on start makes a 4x4 grid of tiles. These tiles are all blank. Two Array variables hold the position of 8 pairs of images. Then when you click a tile it is uncovered and you...
11
by: Kostatus | last post by:
I have a virtual function in a base class, which is then overwritten by a function of the same name in a publically derived class. When I call the function using a pointer to the derived class...
3
by: Ufit | last post by:
I must precisely measure the time of calculation. f.ex clock_t begin,finish,time; begin=clock(); Calculations(); finish=clock(); time=finish-begin; but unfortunatelly finish is equal to...
2
by: Chua Wen Ching | last post by:
Hi there. I think in vb6, i can use GetTickCount easily by accessing the user32.dll (hmm.. can't remember what is the dll name, but something like that) Is there any code in the...
1
by: Dark74 | last post by:
Vladimir Nesterovsky wrote: > If you realy need to measure short time use rathe > QueryPerformanceCounter > and QueryPerformanceFrequency instead of GetTickCount. > -- > Vladimir Nesterovsky >...
23
by: EOS | last post by:
Hi, As the title indicated, does anyone know the equivalent of GetTickCount() function in C/C++ for C#? The function is supposed to return time elapsed since the computer/device is booted in...
2
by: Don Miller | last post by:
Can I call GetTickCount straight from ASP? If so how do I do it? Thanks. Don
7
beacon
by: beacon | last post by:
I'm writing a program as an assignment that takes 5 sorting algorithms and and tests for the amount of time and the number of comparisons it takes to um, sort an array. I have run into some...
1
by: Inebas | last post by:
Hi Guys, I got an assignment to calculate the execute time difference a code written with threads and one without. I got the algorithm working but GetTickCount() return the same number before and...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.