473,800 Members | 2,738 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

measuring 1/100th seconds, what function?

Hello.

I'm doing a Rubik's Cube timer, so I need a function to measure 100ths of
a second. I've browsed through the library reference of python.org, but I
didn't find anything that struck me as 'the perfect fit'. Either it was
system dependent, or it was too grainy (lo-res), or... something else.

so, I need a function which satisfies (in order of importance):

1. It can be used to measure time in the range of up to approximately 1
minute with an accuracy down to 100th-seconds (that's 60000~65536
different values). Better accuracy is a bonus, longer time-frame is a
bigger bonus.

2. it must run on any version of windows upon which python 2.4 can run
(target systems), and run on my system (debian/sarge) __ without the need
for changing the code dependent of environment; any supported
non-Linux/non-windows sytem is a bonus, other supported Linuxes (sp?) is a
bigger bonus (however, I don't expect that it will _not_ work dependent of
distroes)

I'm sorry for asking about such a triviality, but hey, if I can't get it
by RTFM, TFM is buggy ;)

Jonas Kölker

Jul 18 '05 #1
8 1721
Jonas Kölker wrote:
I'm doing a Rubik's Cube timer, so I need a function to measure 100ths of
a second. I've browsed through the library reference of python.org, but I
didn't find anything that struck me as 'the perfect fit'. Either it was
system dependent, or it was too grainy (lo-res), or... something else.
It usually helps to specify what you looked at, and perhaps why you
didn't think it was acceptable, to avoid us retracing your steps...
so, I need a function which satisfies (in order of importance):

1. It can be used to measure time in the range of up to approximately 1
minute with an accuracy down to 100th-seconds (that's 60000~65536
different values). Better accuracy is a bonus, longer time-frame is a
bigger bonus.

2. it must run on any version of windows upon which python 2.4 can run


These two constraints cannot be met simultaneously, I believe.
Windows98 does not provide adequate resolution in the timer.

If you are willing to forego Win98 and use only the real Windows OSes,
then I think you get roughly (?) 10ms resolution already with
time.time(). Linux probably gives 1ms resolution or better in pretty
much all cases with time.time().

-Peter
Jul 18 '05 #2
On 2004-08-10, Jonas Kölker <jo**********@y ahoo.com> wrote:
I'm sorry for asking about such a triviality, but hey, if I
can't get it by RTFM, TFM is buggy ;)


Remember to submit a patch when you figure out how to fix the
bug.

--
Grant Edwards grante Yow! .. One FISHWICH
at coming up!!
visi.com
Jul 18 '05 #3
[Jonas Kölker]
I'm doing a Rubik's Cube timer, so I need a function to measure
100ths of a second. ...


Assuming you want to compute wall-time deltas (as opposed to CPU-time
deltas), about the best you can do x-platform is

if sys.platform == "win32":
from time import clock as now
else:
from time import time as now

Then use now(). Unsure which branch Cygwin should take. It's up to
you to determine whether it works "well enough" on each platform you
care about. Note that on a box connected to a network time-correction
service, time.time can appear to "run backwards" briefly at
unpredictable times. The same kind of thing can happen on multi-CPU
boxes -- or not, depending on piles of platform details.
Jul 18 '05 #4
On Tue, 10 Aug 2004 17:30:14 -0400, Peter Hansen <pe***@engcorp. com> wrote:
Jonas Kölker wrote:
I'm doing a Rubik's Cube timer, so I need a function to measure 100ths of
a second. I've browsed through the library reference of python.org, but I
didn't find anything that struck me as 'the perfect fit'. Either it was
system dependent, or it was too grainy (lo-res), or... something else.


It usually helps to specify what you looked at, and perhaps why you
didn't think it was acceptable, to avoid us retracing your steps...
so, I need a function which satisfies (in order of importance):

1. It can be used to measure time in the range of up to approximately 1
minute with an accuracy down to 100th-seconds (that's 60000~65536
different values). Better accuracy is a bonus, longer time-frame is a
bigger bonus.

2. it must run on any version of windows upon which python 2.4 can run


These two constraints cannot be met simultaneously, I believe.
Windows98 does not provide adequate resolution in the timer.

If you are willing to forego Win98 and use only the real Windows OSes,
then I think you get roughly (?) 10ms resolution already with
time.time(). Linux probably gives 1ms resolution or better in pretty
much all cases with time.time().

On windows I like to use time.clock()
For NT4 with python 2.3.2 (yeah I ought to upgrade both ;-)
from time import time,clock
min(filter(None ,[-(time()-time()) for i in xrange(100000)])) 0.0099999904632 568359 min(filter(None ,[-(clock()-clock()) for i in xrange(100000)])) 5.8666657594130 811e-006

IOW, time apparently gets the NT4 basic os time slice delta (10ms),
whereas clock tries to get something better (and it's pretty good).
The filter call is because time()-time() makes a lot of zeroes.
clock() is fast enough not to require it. Not one zero in 100k, anyway. min([-(clock()-clock()) for i in xrange(100000)])

5.8666656741479 528e-006

And that's not the minimum resolution of the timer clock() uses, it's
near the minimum time between two readings you can get from python.
Maybe some other loop mechanism can get two two samples faster and
then subtract them. A game for someone ;-)

Regards,
Bengt Richter
Jul 18 '05 #5
Bengt Richter wrote:
On windows I like to use time.clock() [snip samples showing better resolution than time.time()] IOW, time apparently gets the NT4 basic os time slice delta (10ms),
whereas clock tries to get something better (and it's pretty good).


All true, though the OP said he wanted code that would work on both
platforms (though Tim's response shows how trivial it is to
dynamically pick the best routine).

Presumably there's a human involved somewhere, plus a multitasking
OS with other things going on, and Python as well (not widely known
as a good hard realtime language ;-), so going for the extra
resolution of time.clock() is likely to be an exercise in higher
resolution, but no better accuracy...

-Peter
Jul 18 '05 #6
Tim Peters <ti********@gma il.com> wrote:
Note that on a box connected to a network time-correction
service, time.time can appear to "run backwards" briefly at
unpredictable times.


This will never happen if you're running NTP. NTP does gradual
adjustments to the clock rate to ensure that the system clock is always
monotonically increasing.

It can happen if you're running some kind of time sync service other
than NTP. Why anybody would want to do such a thing is beyond me.
Jul 18 '05 #7
Roy Smith <ro*@panix.co m> writes:
Tim Peters <ti********@gma il.com> wrote:
Note that on a box connected to a network time-correction
service, time.time can appear to "run backwards" briefly at
unpredictable times.


This will never happen if you're running NTP. NTP does gradual
adjustments to the clock rate to ensure that the system clock is always
monotonically increasing.


ntp only works well if your clock rate is very consistent. On all of
the laptops I've used, I get frequent adjustments:

Aug 6 20:30:45 localhost ntpd[911]: time reset -0.472600 s
Aug 5 22:04:57 localhost ntpd[919]: time reset +0.670974 s
Aug 5 22:34:06 localhost ntpd[919]: time reset +0.884625 s
Aug 5 23:13:54 localhost ntpd[919]: time reset -0.376758 s

I don't see any reason in principle ntp couldn't allow a greater
offset between the local machine and the servers, and use gradual
adjustments in this case. But it doesn't.

Dan
Jul 18 '05 #8
In article <87************ @uwo.ca>, Dan Christensen <jd*@uwo.ca> wrote:
Roy Smith <ro*@panix.co m> writes:
Tim Peters <ti********@gma il.com> wrote:
Note that on a box connected to a network time-correction
service, time.time can appear to "run backwards" briefly at
unpredictable times.


This will never happen if you're running NTP. NTP does gradual
adjustments to the clock rate to ensure that the system clock is always
monotonically increasing.


ntp only works well if your clock rate is very consistent. On all of
the laptops I've used, I get frequent adjustments:

Aug 6 20:30:45 localhost ntpd[911]: time reset -0.472600 s
Aug 5 22:04:57 localhost ntpd[919]: time reset +0.670974 s
Aug 5 22:34:06 localhost ntpd[919]: time reset +0.884625 s
Aug 5 23:13:54 localhost ntpd[919]: time reset -0.376758 s

I don't see any reason in principle ntp couldn't allow a greater
offset between the local machine and the servers, and use gradual
adjustments in this case. But it doesn't.

Dan


I stand corrected. Thank you.
Jul 18 '05 #9

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

Similar topics

1
12346
by: NotGiven | last post by:
Below is a good elapsed time function I found. However, I'd like to return total seconds instead of broken down into days, hours, minutes & seconds. In other words, I want "125" instead of "2 minutes 5 seconds". Any ideas? Thanks very much! function calcElapsedTime($time) { // calculate elapsed time (in seconds!) $diff = time()-$time;
6
46118
by: Kription | last post by:
Hello, I am having a nightmare of a time getting seconds converted to hour-minute-seconds I have a third party application that outputs only in seconds since so if someone has been logged in for 1 minute, the time value would be 60, if they were on for 5 minutes and 3 seconds the value would be 303
6
2332
by: Mudge | last post by:
I'm writing PHP Web sites that are database driven with mysql. I'm looking for ways to measure the performance (speed) of my php code, so that I can find ways to write the fastest php code. Any suggestions? Nick
1
2994
by: Carlo Filippini | last post by:
Hi I am trying to measure the perofrmance of a wireless link using maily ftp. Unfortunately get and put from Net::FTP do not give me an measure of the performances. I am sure somebody must have done this already. I just need a DOS like "xxxx bytes transferred in xxx seconds", should be quite simple... Any suggestion? Thanks Carlo
74
7764
by: Dominik Wallner | last post by:
Hi! I'm currently implementing a program which measures voltages through an external USB-AD-converter. It should output those values as time/voltage pairs. My problem is to measure the time to output (time elapsed since program start would do just fine) - it should be as precise as possible, as there may be only differences in milliseconds between two measurements.
20
1988
by: upperclass | last post by:
Hi, I'm trying to find a decent way of measuring the running time of a long-running program. Say, the running time ranges from several seconds to more than a day. The standard clock() function seems inadequate for this task. (I read somewhere in this group that clock_t would likely overflow after <1 hour).
2
4645
by: upperclass | last post by:
Hi, I'm trying to find a decent way to measure program running time. I know clock() is probably the standard way of doing it but clock_t overflows too quickly. The target program running time ranges from a few seconds to a day. Is there a decent+portable way to deal with this? Thank you.
7
18338
by: i12know | last post by:
Hi guys, I have tried a lot of code and read forums discussing about C or C++ functions that measures time in microsecond, but there still seems to be confusions about that. Can anyone tell me again how do I get the time up to 1 microsecond in resolution? It doesn't need to be very precise in measuring the time, but at least need to be able to measure 1 microsecond the minimum. I saw in some forum that says usleep() gives microsecond delay,...
9
3319
by: Ross | last post by:
I'm a newbie at this, and have searched a lot but can't find something that seems appropriate for measuring a recurring elapsed time. Creating an object with: var mydate = new Date(); seems clear, as is creating a second: nowTime = new Date(); and getting a difference between the two. My quesiton is what if you have many, maybe thousands of intervals you wish to measure? Should I do: nowTime = new Date(); with every pass of a...
0
9690
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
9550
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10501
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
10273
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...
0
9085
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7574
isladogs
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
4149
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
3764
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2944
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.