Egore
asked on
High-res timing
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
Help is very much appreciated,
- Alex
You must use the multimedia timers. Look for timeSetEvent in the help.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Ignore last link I give,here I will give enough info to you...
Continue:
Continue:
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.
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.
//Hi , Egore
//Here is the way to initialize it.
LONGLONG perf_cnt;
LONGLONG the_time;
QueryPerformanceFrequency( (LARGE_INT EGER *) &perf_cnt));
// read initial time
QueryPerformanceCounter((L ARGE_INTEG ER *) &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
//Here is the way to initialize it.
LONGLONG perf_cnt;
LONGLONG the_time;
QueryPerformanceFrequency(
// read initial time
QueryPerformanceCounter((L
//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
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.
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.