Solved

High-res timing

Posted on 2000-03-20
6
240 Views
Last Modified: 2010-04-02
Within Windows 95/98/2000 how can I get timing down to the millisecond resolution?  I have been using timeGetTime() but, because of the WinAPI overhead, it is too slow.  Also, timeGetTime() is only accurate within approximately 8ms (I think) and I need timing that is accurate at the 1 or 2ms level.

Help is very much appreciated,
- Alex
0
Comment
Question by:Egore
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
6 Comments
 
LVL 1

Expert Comment

by:wildy
ID: 2635264
You must use the multimedia timers. Look for timeSetEvent in the help.
0
 
LVL 5

Accepted Solution

by:
Wyn earned 100 total points
ID: 2635275

You'd use mutilmedia-timer below for high resolution:

BOOL QueryPerformanceFrequency(
  LARGE_INTEGER *lpFrequency   // pointer to current frequency);

BOOL QueryPerformanceCounter(
  LARGE_INTEGER *lpPerformanceCount   // pointer to counter value);

Check for more:
Win32 Multithreading Performance
http://msdn.microsoft.com/library/techart/msdn_threadli.htm


Regards
W.Yinan
0
 
LVL 5

Expert Comment

by:Wyn
ID: 2635278
Ignore last link I give,here I will give enough info to you...

Continue:
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 5

Expert Comment

by:Wyn
ID: 2635284
The Pentium processor and most PC compatible processors such as AMD support a high-resolution Performance Counter, which can provide a resolution of less than **one microsecond**.
The QueryPerformanceFrequency function is used to determine the actual frequency of the counter.  This is the numeric value that the Performance Counter will increase by in 1 second.

The QueryPerformanceCounter function is used to read the Performance Counter, which may be divided by the counter frequency to determine the time in seconds.

Both of these functions take a pointer to a LARGE_INTEGER union, which will be filled with the requested value if the function is successful.

The function will return 0 on failure, or non-zero on success.
0
 
LVL 5

Expert Comment

by:Wyn
ID: 2635326
//Hi , Egore
//Here is the way to initialize it.

LONGLONG perf_cnt;
LONGLONG the_time;


QueryPerformanceFrequency((LARGE_INTEGER *) &perf_cnt));

// read initial time

QueryPerformanceCounter((LARGE_INTEGER *) &the_time);

//you get the current count stored into the_time.


The QueryPerformanceCounter function retrieves the current value of the high-resolution performance counter (if one exists on the system). By calling this function at the beginning and end of a section of code, an application essentially uses the counter as a high-resolution timer. For example, suppose that QueryPerformanceFrequency indicates that the frequency of the high-resolution performance counter is 50,000 counts per second. If the application calls QueryPerformanceCounter immediately before and immediately after the section of code to be timed, the counter values might be 1500 counts and 3500 counts, respectively. These values would indicate that .04 seconds (2000 counts) elapsed while the code executed."



Okay,hope helpful and good luck

Regards
W.Yinan
0
 
LVL 5

Expert Comment

by:Wyn
ID: 2635336
Btw: You can call QueryPerformanceCounter() later and check with the_time to get hwo many counters elapse.

Because you already know counter times per second.Then you can figure out the time in between.This resolutionn is very high but I figure the TimegetTime() should around 1 millisecond.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
mixing C++ & C# in Vis Studio 2013 7 280
Task manager indicates my c++ program memory consumption is growing? 12 164
Android development question 2 109
print bytes of an integer 6 48
Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

751 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question