473,577 Members | 3,213 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

System Clock


I need to be able to measure a time interval in milliseconds on a windows
machine. I have tried using time.clock() but it appears to measure time in
seconds...Is there a way to measure time more precisely?


James Harriman
Jul 18 '05 #1
3 6688

"James Harriman" <v3***@unb.ca > wrote in message
news:9S******** ***********@urs a-nb00s0.nbnet.nb .ca...

I need to be able to measure a time interval in milliseconds on a windows machine. I have tried using time.clock() but it appears to measure time in seconds...Is there a way to measure time more precisely?

For floats, what matters is the resolution (precision), not the unit.
On AMDK2-385, Win 98:
a=time.clock(); time.sleep(1); print time.clock()-a 1.01412863105 # correct, seconds
time.clock()-time.clock() -3.0171474548978 949e-005 time.clock()-time.clock() -3.1847667571582 861e-005 time.clock()-time.clock() -3.1009571046070 05e-005 time.clock()-time.clock() -2.9333377995044 43e-005 time.clock()-time.clock() -3.0171474577400 659e-005 time.clock()-time.clock() -3.1009571046070 05e-005 time.clock()-time.clock() -3.1009571102913 469e-005 time.clock()-time.clock() -2.9333378051887 848e-005

This is reproducibly .03+ milleseconds (minus because earlier - later)
== 30 microseconds.

Now speed up a bit: tc = time.clock
tc()-tc() -2.8495281526375 038e-005 tc()-tc() -2.7657185000862 228e-005 tc()-tc() -3.0171474520557 24e-005 tc()-tc() -2.6819088532192 836e-005 tc()-tc() -2.8495281526375 038e-005 tc()-tc() -2.7657185000862 228e-005 tc()-tc() -2.8495281526375 038e-005 tc()-tc() -2.7657185000862 228e-005 tc()-tc() -2.7657185000862 228e-005

The average is about 28 microsecs, so time.clock lookup appears to be
measurebly about 1 microsecond, but anything much smaller would be
lost in the noise on this system.

(Oddly, I also get this: tc()-tc(); tc()-tc()

-2.8495281412688 2e-005
-1.4247640820030 938e-005
which I have not figured out yet)

Terry J. Reedy

Jul 18 '05 #2
On Fri, Nov 07, 2003 at 12:40:37AM +0000, James Harriman wrote:

I need to be able to measure a time interval in milliseconds on a windows
machine. I have tried using time.clock() but it appears to measure time in
seconds...Is there a way to measure time more precisely?

From http://www.python.org/doc/lib/module-time.html

On Unix, return the current processor time as a floating point number
expressed in seconds. The precision, and in fact the very definition of the
meaning of `processor time'' , depends on that of the C function of the same
name, but in any case, this is the function to use for benchmarking Python
or timing algorithms.

On Windows, this function returns wall-clock seconds elapsed since the
first call to this function, as a floating point number, based on the Win32
function QueryPerformanc eCounter(). The resolution is typically better than
one microsecond.

Return the time as a floating point number expressed in seconds since
the epoch, in UTC. Note that even though the time is always returned as a
floating point number, not all systems provide time with a better precision
than 1 second. While this function normally returns non-decreasing values,
it can return a lower value than a previous call if the system clock has
been set back between the two calls.


Jul 18 '05 #3
On Thu, Nov 06, 2003 at 10:47:19PM -0500, Terry Reedy wrote:


(Oddly, I also get this:
tc()-tc(); tc()-tc() -2.8495281412688 2e-005
-1.4247640820030 938e-005
which I have not figured out yet)

I think this indicates there is more than one cost path down into the timing
machinery. Consider:

-3.9339065551757 812e-06
-9.5367431640625 e-07
-1.0728836059570 312e-06
-1.0728836059570 312e-06
-1.0728836059570 312e-06
-9.5367431640625 e-07
-9.5367431640625 e-07

It appears to me as though making subsequent calls to time.time() in rapid
succession allows one to exploit an optimization somewhere.

Perhaps some hardware-level caching?


Jul 18 '05 #4

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

Similar topics

by: Valiz | last post by:
Hi, I am updating system time with IRIG time source which sends irregular pulses as shown below 11000011111100111111111111111111....(1-IRIG present and 0-IRIG not present) I need to update system time when I find a steady pulse or a series of 1's say for a span of 10-15 seconds. Is there a way to implement this in VB6? Thanks in advance....
by: David Lindgren | last post by:
Hello. I am trying to figure out a way to determine if the user has resetted the system clock between two times of running my application. One idea I have is that I could check the modified date of a system file which I "know" is changed regulary (every day) and compare that to the current time. If the modified date is later than current...
by: Partho Choudhury | last post by:
Hi all: I need to add a snippet which access the system time (upto atleast milliseconds) using ANSI std. C++. I cannot use MFC and Win32 APIs in my program for now for various reasons. Is there something like this in ANSI C++ which allows access up to milliseconds. I know that time.h and CTime allow access up to the second level, but I need...
by: eugene | last post by:
Is there any issue re-setting system time while DB2 database is online and the system clock is ahead. The database is actually a 24x7 operational and a unscheduled shutdown would be a problem. Thanks, -Eugene
by: MLH | last post by:
I wish to give someone an A97 database they can install on their PC as a runtime application. I want them to click a button on a form (frmDocumentMyPC). I want to document as much useful information about the PC as possible, save the data in table(s) and print a nice report. I know how to run IPconfig and read its output into Access tables. ...
by: jUrner | last post by:
Hello all I have the problem of how to calculate the resolution of the system clock. Its now two days of head sratching and still there is nothing more than these few lines on my huge white sheet of paper stiring at me. Lame I know. import time
by: Moikel | last post by:
Hello, I'm writing a program that requires that I generate random numbers. I'm using the C rand()function. I want to use the system clock as a seed for the function. How do I read the system clock in Windows? (Please state any libraries I'm going to need etc). Thanks, Moikel
by: Carlos Lozano | last post by:
I have requirement to pause the system clock until a certain event (Win XP). Then the clock will be resumed to the real time. I think it can be done using core functions and/or redirecting the time/date call to a temporary service routines, then redirect to the original. I will appreciate any ideas to go in the right direction. Carlos
by: David H | last post by:
I am looking for a way to either run a program in the system tray, or (ideally) replace the system clock with my own custom clock app. I know I can use NotifyIcon to put an icon in the tray, but I'm limited to a 16x16 icon with this solution. I am working on a clock app that needs more space. Any suggestions/advice appreciated. Thanks, ...
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...
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
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...
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...
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
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
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
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...

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.