Solved

C++ Timer

Posted on 1998-07-21
5
260 Views
Last Modified: 2011-09-20
I am currently writing a program using Visual C++ under Windows 95.
I would like to be able to time a peripherial device down to as accurate a time as possible, if possible in micro seconds. Is there any functions / techniques that will be able to give me this accurate a method of timing.

This program has to be accurate on various machines with different clock speeds.
The only solution I can find is the Performance Counter, but this is not always supported.
0
Comment
Question by:vally
[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 Comments
 

Author Comment

by:vally
ID: 1168214
Edited text of question
0
 
LVL 15

Expert Comment

by:Tommy Hui
ID: 1168215
You'll need to do a couple of things:

Use the multimedia timer: timeSetEvent().

However, timeSetEvent is not really accurate, so that you can do is use timeSetEvent for a one-time event, 1 millisecond before the actual time. Then when the timer fires, use QueryPerformanceCounter() to count until the actual time has occurred.
0
 

Author Comment

by:vally
ID: 1168216
When I said time it down, I meant as in how long it took to finish its task, eg transfer a block of data.

Besides QueryPerformanceCounter is out as it is not always supported
0
 
LVL 11

Expert Comment

by:alexo
ID: 1168217
QueryPerformanceCounter() is supported on Pentuims and above, Pentium clones, Alphas, etc.  What more do you need?

Thui, your answer sounds strangely familiar :-)
0
 
LVL 23

Accepted Solution

by:
chensu earned 100 total points
ID: 1168218
Use the timeGetTime function. The timeGetTime function retrieves the system time, in milliseconds. The system time is the time elapsed since Windows was started.

DWORD dwStartTime = ::timeGetTime();
.
DWORD dwEndTime = ::timeGetTime();

DWORD dwHowLong = dwEndTime - dwStartTime;

Windows NT: The default precision of the timeGetTime function can be five milliseconds or more, depending on the machine. You can use the timeBeginPeriod and timeEndPeriod functions to increase the precision of timeGetTime. If you do so, the minimum difference between successive values returned by timeGetTime can be as large as the minimum period value set using timeBeginPeriod and timeEndPeriod. Use the QueryPerformanceCounter and QueryPerformanceFrequency functions to measure short time intervals at a high resolution,

Windows 95: The default precision of the timeGetTime function is 1 millisecond. In other words, the timeGetTime function can return successive values that differ by just 1 millisecond. This is true no matter what calls have been made to the timeBeginPeriod and timeEndPeriod functions.

0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
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.

756 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