473,738 Members | 8,397 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 8704
noleander wrote:
Question: Is there a way on Windows (Visual C++) to get current time with
microsecond (or better) accuracy?


Why not use QueryPerformanc eCounter/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 QueryPerformanc eCounter/QueryPerformanc eFrequency 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 QueryPerformanc eCounter/QueryPerformanc eFrequency 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
3637
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 identity. In order to correct this problem I've modified the Machine.config file in the \Microsoft.Net\Framework\v1.1.4322 folder. However, this didn't solve the problem; instead of using the user id and password specified in Machine.Config, the...
3
857
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, please?? "Onstart" - I set: Timer1.Interval = 5000 Timer1.Enabled = True
1
3309
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 abort the timer before it hits the limit - it's the classic timeout type thing. I'll readily admit I'm no expert on C++, but after a trawl of the WWW pages, there appears to be two solutions depending on whether it's Linux or Windows.
14
1500
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
9542
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 problem is it doesn't appear to be running any of my code whatsoever. I dropped a Timer Control on the designer, set it to disabled with an interval of 5000, went to the code window and on the OnStart Event, typed in: Timer1.Enabled=True
12
2122
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
14403
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 functionality of the sub working fine but I cannot figure out how to run the timer. The sub DoSomethingHere() needs to run every 60 seconds. It doesn't need to change the interval or anything like that. It just needs to run every 60 seconds as long as...
15
6731
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 OK, but how do I put in the timer so that I can write the file on schedule? The idea behind this project is to help me monitor remote computers in a production environment to make sure that they are up and running. I currently synchronize files on...
8
1116
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
8969
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9476
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9335
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9263
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6053
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4570
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3279
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2745
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2193
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.