473,795 Members | 3,231 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

time.clock() problem under linux (precision=0.01 s)

I have to measure the time of a while loop, but with time.clock i
always get 0.0s, although python manual sais:
"this is the function to use for benchmarking Python or timing
algorithms"

So i tested timer functions capabilities with a short script:

import time
import os

def test_timer_func (func):
print 'min time-time: %.10f'%min(abs( func()-func()) for i in
xrange(10**5))
print 'max time-time: %.10f'%max(abs( func()-func()) for i in
xrange(10**5))

dt = 0.0
loopcount = 0
t = func()

while dt==0.0:
dt = func() - t
loopcount += 1

print "min measurable loop time : %.10f"%dt
print 'loopcount while dt==0 :',loopcount
print '\n time.clock()'
test_timer_func (time.clock)

print '\n time.time()'
test_timer_func (time.time)

print '\n os.times()'
ot = os.times
test_timer_func (lambda:ot()[4])
My output is:

time.clock()
min time-time: 0.0000000000
max time-time: 0.0100000000
min measurable loop time : 0.0100000000
loopcount while dt==0 : 2703

time.time()
min time-time: 0.0000019073
max time-time: 0.0000460148
min measurable loop time : 0.0000050068
loopcount while dt==0 : 1

os.times()
min time-time: 0.0000000000
max time-time: 0.0100000007
min measurable loop time : 0.0099999998
loopcount while dt==0 : 2515
So the precision of time.clock is 0.01s under my ubuntu linux system,
which means it's not suitable for benchmarking. (i want to benchmark
the fps in my pygame+pyode program and it needs at least 0.001s
precision)

time.time seems much better solution, but python manual sais: "not all
systems provide time with a better precision than 1 second"

Should i use time.clock or time.time to be more crossplatform?
Is time.time ok for windows? (time()-time() != 0.0)

nszabolcs

Aug 18 '05 #1
3 3157
On 18 Aug 2005 04:07:18 -0700, "Szabolcs Nagy" <ns*******@gmai l.com>
declaimed the following in comp.lang.pytho n:

Should i use time.clock or time.time to be more crossplatform?
Is time.time ok for windows? (time()-time() != 0.0)
PythonWin 2.3.5 (#62, Feb 9 2005, 16:17:08) [MSC v.1200 32 bit (Intel)]
on win32.
Portions Copyright 1994-2001 Mark Hammond (mh******@skipp inet.com.au) -
see 'Help/About PythonWin' for further copyright information.
import time
time.time() - time.time() 0.0 time.clock() - time.clock() -1.2882053580379 413e-006

-- =============== =============== =============== =============== == <
wl*****@ix.netc om.com | Wulfraed Dennis Lee Bieber KD6MOG <
wu******@dm.net | Bestiaria Support Staff <
=============== =============== =============== =============== == <
Home Page: <http://www.dm.net/~wulfraed/> <
Overflow Page: <http://wlfraed.home.ne tcom.com/> <

Aug 18 '05 #2
"Szabolcs Nagy" <ns*******@gmai l.com> writes:
time.time seems much better solution, but python manual sais: "not all
systems provide time with a better precision than 1 second"

Should i use time.clock or time.time to be more crossplatform?
Is time.time ok for windows? (time()-time() != 0.0)


You should use the timeit module, which chooses the correct timer to
use for the platform it's running on, as well as working around a
number of other things that trip up people trying to benchmark code.

<mike
--
Mike Meyer <mw*@mired.or g> http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
Aug 19 '05 #3
ncf
Woa, if you don't mind my asking, why do you do a time-cache on your
messages?

Aug 19 '05 #4

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

Similar topics

18
5304
by: bart_nessux | last post by:
I need a script to call several functions at the same time. How does one call more than one function simultaneously?
8
3409
by: peterbe | last post by:
What's the difference between time.clock() and time.time() (and please don't say clock() is the CPU clock and time() is the actual time because that doesn't help me at all :) I'm trying to benchmark some function calls for Zope project and when I use t0=time.clock(); foo(); print time.clock()-t0 I get much smaller values than when I use time.clock() (most of them 0.0 but some 0.01) When I use time.time() I get values like...
3
2530
by: Russell Warren | last post by:
Does anyone know how long it takes for time.clock() to roll over under win32? I'm aware that it uses QueryPerformanceCounter under win32... when I've used this in the past (other languages) it is a great high-res 64-bit performance counter that doesn't roll-over for many (many) years, but I'm worried about how many bits Python uses for it and when it will roll over. I need it to take years to roll over. I'm also aware that the actual...
20
12607
by: Jean Johnson | last post by:
Hello - I have a start and end time that is written using the following: time.strftime("%b %d %Y %H:%M:%S") How do I calculate the elapsed time? JJ
5
7658
by: Tobiah | last post by:
The manual says: On Unix, return the current processor time as a floating point number expressed in seconds. So I ran this program: #!/usr/bin/python import time
5
5653
by: yinglcs | last post by:
Hi, I am following this python example trying to time how long does an operation takes, like this: My question is why the content of the file (dataFile) is just '0.0'? I have tried "print >>dataFile, timeTaken" or "print >>dataFile,str( timeTaken)", but gives me 0.0. Please tell me what am I missing?
37
4694
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
12
3311
by: pekka | last post by:
I'm trying to measure user input time with my Timer class object. It isn't as easy as I expected. When using std::cin between timer start and stop, I get zero elapsed time. For some unknown reason, the clock seems to stop ticking during execution of std::cin. Here's my code: #include <ctime> #include <iostream> #include <string>
8
1855
by: Theo v. Werkhoven | last post by:
hi, In this code I read out an instrument during a user determined period, and save the relative time of the sample (since the start of the test) and the readback value in a csv file. #v+ from datetime import * from time import * from visa import *
0
9672
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
9519
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
10213
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
10163
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
10000
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
9037
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
4113
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
3721
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2920
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.