473,386 Members | 1,752 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,386 software developers and data experts.

Microsecond timer available on Windows?

Hi. I'm doing some speed optimization on my Visual C++ program. I'm using
timers throughout the program. I'm calling ftime() which works well, but
only returns current time to a millisecond accuracy. I've gotten to the
point where I now need even more precision in my timers.

Many unix platforms have a function gettimeofday() which has microsecond
accuracy, but this function is not available on Windows, apparently.

Question: Is there a way on Windows (Visual C++) to get current time with
microsecond (or better) accuracy?
Nov 17 '05 #1
3 8663
noleander wrote:
Question: Is there a way on Windows (Visual C++) to get current time with
microsecond (or better) accuracy?


Why not use QueryPerformanceCounter/Frequency?

--
Greetings
Jochen

My blog about Win32 and .NET
http://blog.kalmbachnet.de/
Nov 17 '05 #2
noleander wrote:
Hi. I'm doing some speed optimization on my Visual C++ program.
I'm using timers throughout the program. I'm calling ftime() which
works well, but only returns current time to a millisecond accuracy.
I've gotten to the point where I now need even more precision in my
timers.

Many unix platforms have a function gettimeofday() which has
microsecond accuracy, but this function is not available on Windows,
apparently.
Actually, it has microsecond resolution. It's unlikely that it has
microsecond accuracy or precision on the vast majority of *nix platforms.

Question: Is there a way on Windows (Visual C++) to get current time
with microsecond (or better) accuracy?


Use QueryPerformanceCounter/QueryPerformanceFrequency to measure short
intervals at high resolution. On most modern PCs, QPC measures in CPU
clock cycles.

-cd
Nov 17 '05 #3
Once again, outsanding, fast and accurate answers.
Thanks!
"Carl Daniel [VC++ MVP]" wrote:
noleander wrote:
Hi. I'm doing some speed optimization on my Visual C++ program.
I'm using timers throughout the program. I'm calling ftime() which
works well, but only returns current time to a millisecond accuracy.
I've gotten to the point where I now need even more precision in my
timers.

Many unix platforms have a function gettimeofday() which has
microsecond accuracy, but this function is not available on Windows,
apparently.


Actually, it has microsecond resolution. It's unlikely that it has
microsecond accuracy or precision on the vast majority of *nix platforms.

Question: Is there a way on Windows (Visual C++) to get current time
with microsecond (or better) accuracy?


Use QueryPerformanceCounter/QueryPerformanceFrequency to measure short
intervals at high resolution. On most modern PCs, QPC measures in CPU
clock cycles.

-cd

Nov 17 '05 #4

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

Similar topics

3
by: brian | last post by:
I have an ASP.Net application that uses impersonation. This works fine for accessing/executing the application. However, the app utilizes a timer, that when fired uses the <machine>ASPNET...
3
by: Henrik H | last post by:
Hi all! I have a Windows service, where I want to use a timer.. But it does not Seems work?? It does not catch the Timer1.tick event ??? But the code works on a form??? Can anyone help me,...
1
by: John | last post by:
I'm trying to write a program that's run on both Windows 98 and Linux. I need a timer, that I can start and when it hits a limit, it needs to call a callback function. I also need to be able to...
14
by: Mathieu | last post by:
Hi all, I just want to know how to use a System.Windows.Forms.Timer in class. I know how to use it on a form, but I don't know how to "put" a timer in a class (DLL) Thx !!!
3
by: Scott H | last post by:
Hello, I'm having a go at writing my first Windows Service in VB.NET and I'm having a problem. I have it installed ok and started the service sucessfully, I can stop it, and restart it fine, the...
12
by: John | last post by:
Hi I have a timer on my form. The problem is no matter how large an interval I set, the timer_tick event always gets called very fast. What am I doing wrong? Thanks Regards
4
by: Lauren Quantrell | last post by:
I have just put together a vb.net app and now need to provide it to users. This application needs to run the code in a sub every 60 seconds from a Windows Service application. I have the...
15
by: Scott M. | last post by:
Hi, I'm an old VB6 guy just starting out in VB.Net using Visual Studio Express. I want to build a simple console app that will create a simple text file every 10 minutes. I can create the file...
8
by: Jerry Spence1 | last post by:
Do Timers operate on the UI thread, or do they have it's own thread? I'm trying to assess the pros and cons for using a timer or a thread for a certain application. -Jerry
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.