473,976 Members | 32,574 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

time.clock() going backwards??

Hello,

I experimented something very strange, a few days ago. I was debugging an
application at a customer's site, and the problem turned out to be that
time.clock() was going "backwards" , that is it was sometimes (randomically)
returning a floating point value which was "less than" the value returned by
the previous invokation. The computer was a pretty fast one (P4 3Ghz I think,
running Windows XP), and this happened only between very close invokations of
time.clock().

I have triple-verified this, including printing the repr() of the floating
point number and verifying it was really minor than the previous value by a few
microseconds. In other words, I'm absolutely positive that it's not a mistake
on my side, but that time.clock() was really apparently "jumping backward".
This was confusing the hell out of my application, of course, and I just hacked
it so to ignore these bogus reads, and just reading off again. Since the error
was just of a few microseconds, reading time.clock() again produces a number
which was higher than what I had before, and thus OK for my application.

I was wondering if someone had experimented this behaviour before. I tried
googling but to no effect. Is it possible this to be a bug in Python itself
(maybe, shooting at the moon, in the conversion between the 64bit performance
counter and the floating point representation returned by time.clock()), or
could it be a bug in Windows itself or the mother board drivers (buf if so,
wouldn't other application start going mad)?
--
Giovanni Bajo
Aug 25 '06
18 6302
Claudio Grondi wrote in news:ec******** **@newsreader2. netcologne.de in
gmane.comp.pyth on.general:
Tim Roberts wrote:
>"Tim Peters" <ti********@gma il.comwrote:
>>
It is much simpler than that. With a multiprocessor HAL, including
on a dual-core or hyperthreaded system, QueryPerformanc eCounter
returns the raw cycle counter (RDTSC). However, on Windows XP, the
operating system does not synchronize the cycle counters on multiple
processors, and they can be actually be millions of cycles apart.

This was a change from previous systems. On NT4 and Win2000, the
operating actually rewrote the cycle counters on the second (and
beyond) processors to align them to the first processor, so the delta
was usually only a dozen or two cycles. XP does not appear to do
that. I think that is a huge mistake, since it renders
QueryPerforman ceCounter non-monotonic.

How does it come, that processors on same mainboard run at different
speeds? Do they have separate clock-pulse generators?
I don't see any claim above that they run at different speeds, only
that the counters are several million cycles apart, IOW running at the
same speed but with different initial values, or more likely starting
at different times.

For processors that run at (say) 2GHz, several million (say 10 million)
represents a difference of 10e6/2e9 = 0.005 seconds between when the
processors were sufficiently powered up to start counting cycles.

Rob.
--
http://www.victim-prime.dsl.pipex.com/

Aug 28 '06 #11
Rob Williscroft wrote:
Claudio Grondi wrote in news:ec******** **@newsreader2. netcologne.de in
gmane.comp.pyth on.general:

>>Tim Roberts wrote:
>>>"Tim Peters" <ti********@gma il.comwrote:

>>>It is much simpler than that. With a multiprocessor HAL, including
on a dual-core or hyperthreaded system, QueryPerformanc eCounter
returns the raw cycle counter (RDTSC). However, on Windows XP, the
operating system does not synchronize the cycle counters on multiple
processors , and they can be actually be millions of cycles apart.

This was a change from previous systems. On NT4 and Win2000, the
operating actually rewrote the cycle counters on the second (and
beyond) processors to align them to the first processor, so the delta
was usually only a dozen or two cycles. XP does not appear to do
that. I think that is a huge mistake, since it renders
QueryPerform anceCounter non-monotonic.

How does it come, that processors on same mainboard run at different
speeds? Do they have separate clock-pulse generators?


I don't see any claim above that they run at different speeds, only
that the counters are several million cycles apart, IOW running at the
same speed but with different initial values, or more likely starting
at different times.

For processors that run at (say) 2GHz, several million (say 10 million)
represents a difference of 10e6/2e9 = 0.005 seconds between when the
processors were sufficiently powered up to start counting cycles.

Rob.
If it were so, than why can't the delta of time between the processors
be set to exact zero?
I assume, that it is known how many cycles adjusting the value will
take, so it could be done exactly ... hmmm ...

Claudio Grondi
Aug 28 '06 #12
On 2006-08-28, Claudio Grondi <cl************ @freenet.dewrot e:
>I don't see any claim above that they run at different speeds, only
that the counters are several million cycles apart, IOW running at the
same speed but with different initial values, or more likely starting
at different times.

For processors that run at (say) 2GHz, several million (say 10 million)
represents a difference of 10e6/2e9 = 0.005 seconds between when the
processors were sufficiently powered up to start counting cycles.
If it were so, than why can't the delta of time between the processors
be set to exact zero?
This is
I assume, that it is known how many cycles adjusting the value will
take, so it could be done exactly ... hmmm ...

Claudio Grondi

--
Grant Edwards grante Yow! LIFE is a
at never-ending INFORMERCIAL!
visi.com
Aug 28 '06 #13
Claudio Grondi wrote:
If it were so, than why can't the delta of time between the processors
be set to exact zero?
someone just wrote:
>>>This was a change from previous systems. On NT4 and Win2000, the
operating actually rewrote the cycle counters on the second (and
beyond) processors to align them to the first processor, so the delta
was usually only a dozen or two cycles. XP does not appear to do
that. I think that is a huge mistake, since it renders
QueryPerform anceCounter non-monotonic.
so if you really want to know, you may have to ask microsoft.

</F>

Aug 28 '06 #14
so if you really want to know, you may have to ask microsoft.

footnote: judging from

http://support.microsoft.com/?id=896256

this might be related to advanced power management features in XP. that
note also mentions a hotfix for this.

</F>

Aug 28 '06 #15
On 2006-08-28, Grant Edwards <gr****@visi.co mwrote:
>>For processors that run at (say) 2GHz, several million (say 10
million) represents a difference of 10e6/2e9 = 0.005 seconds
between when the processors were sufficiently powered up to
start counting cycles.
>If it were so, than why can't the delta of time between the
processors be set to exact zero?

This is
Oops. Hit the wrong key. I meant to say:

This is a _Microsoft_Prod uct_. There doesn't have to be a
reason for something to be done in a half-assed manner.
>I assume, that it is known how many cycles adjusting the value
will take, so it could be done exactly
Yup.

--
Grant Edwards grante Yow! People humiliating
at a salami!
visi.com
Aug 28 '06 #16

"Grant Edwards" <gr****@visi.co mWrote:

| On 2006-08-28, Grant Edwards <gr****@visi.co mwrote:
|
| >>For processors that run at (say) 2GHz, several million (say 10
| >>million) represents a difference of 10e6/2e9 = 0.005 seconds
| >>between when the processors were sufficiently powered up to
| >>start counting cycles.
| >
| >If it were so, than why can't the delta of time between the
| >processors be set to exact zero?
| >
| This is
|
| Oops. Hit the wrong key. I meant to say:

Thank god! - I know you are not an idiot - and for some minutes you had me
guessing - I was beginning to think that my brain had finally been destroyed by
drink - trying to figure out this enigmatic post... :-)

- Hendrik

8<-----------------
Aug 29 '06 #17
Grant Edwards wrote:
This is a _Microsoft_Prod uct_. There doesn't have to be a
reason for something to be done in a half-assed manner.
No, it is a quantum effect. If the energy of a clock has a
lower bound, there must be a nonzero probability for it to
run backwards.

See <93**********@n ews.state.mn.us >

SCNR, Ralf
Aug 29 '06 #18
On 2006-08-29, Ralf Muschall <rm*******@teco nt.dewrote:
Grant Edwards wrote:
>This is a _Microsoft_Prod uct_. There doesn't have to be a
reason for something to be done in a half-assed manner.

No, it is a quantum effect. If the energy of a clock has a
lower bound, there must be a nonzero probability for it to
run backwards.

See <93**********@n ews.state.mn.us >

Brain... hurts...

--
Grant Edwards grante Yow! JAPAN is a WONDERFUL
at planet -- I wonder if we'll
visi.com ever reach their level of
COMPARATIVE SHOPPING...
Aug 30 '06 #19

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

Similar topics

13
3308
by: Peter Hansen | last post by:
I would like to determine the "actual" elapsed time of an operation which could take place during a time change, in a platform-independent manner (at least across Linux/Windows machines). Using time.time() doesn't appear to be suitable, since time might jump forwards or backwards at the user's whim, if the system clock is reset, or when a daylight savings time change occurs. Using time.clock() doesn't appear to be suitable on Linux,...
9
2034
by: Fabian | last post by:
I had a very quiet schedule at work today, so I thought I'd finish this script. In theory, it should generate a random time between two moments specified, round it off to a conventional interval if desired, and convert it into text if desired. The text conversion routine is a separate function which could be used more generally if desired. It mostly seems to work ok. Anyone want to either borrow it or show me some horribly obvious flaw...
5
9124
by: Erich Schreiber | last post by:
In the Python Library Reference the explanation of the time.sleep() function reads amongst others: > The actual suspension time may be less than that requested because > any caught signal will terminate the sleep() following execution > of that signal's catching routine. Also, the suspension time may > be longer than requested by an arbitrary amount because of the > scheduling of other activity in the system. I don't understand the...
74
7875
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.
37
4762
by: David T. Ashley | last post by:
I have Red Hat Enterprise Linux 4. I was just reading up about UTC and leap seconds. Is it true on my system that the Unix time may skip up or down by one second at midnight when there is a leap second? By "Unix time" I mean the integer returned by time() and similar functions. I'm concerned about the "down" case. Some of the software I've written
5
2213
by: Charles May | last post by:
Anyone have a simple concept for the best way to store timeclock information in a database. I currently have my table set up like this with a typical daily entry. tcID empID Type Date Time 1 37 'Clockin' 1/18/08 7:45:39 AM 2 38 'Clockin' 1/18/08 7:55:42 AM 3 39 'Clockin' 1/18/08 7:55:42 AM 4 38 'BreakOut' 1/18/08 ...
7
1849
by: Godzilla | last post by:
Hello, I have been reading a thread about time.clock() going backward, which is exactly what I am seeing... the thread generally leaning toward the problem is caused by multi-processor machines. But I am seeing it at a single CPU computer, and running XP. The error I am seeing between two very close invokation of time.clock() is always around 3.5 seconds! This is enough to throw a lot of the timing requirement in the software out of...
0
1213
by: Gabriel Genellina | last post by:
En Tue, 03 Jun 2008 16:58:12 -0300, Pau Freixes <pfreixes@milnou.net> escribió: So the above code corresponds to the standalone version - what about the embedded version? Are you sure it is exactly the *same* code? All those global statements are suspicious, and you don't even need most of them. Note that looking up a name in the global namespace is much slower than using a local name. Also, you're including the time it takes the OS...
0
10349
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
11404
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
11566
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
10903
tracyyun
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
10078
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...
0
6411
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...
0
6548
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
5149
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
3
3756
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.