High-resolution timers

Ben Wolfson wolfson at uchicago.edu
Wed Jan 16 22:46:46 EST 2002


On Wed, 16 Jan 2002 21:32:42 -0600, Mark Hammond wrote:

> Use time.clock() - it will always provide the best timer for the 
> platform.

It acts pretty strangely on all the computers to which I have access:

harper:~> python
Python 2.0 (#1, Feb 26 2001, 17:11:04) [C] on sunos5
Type "copyright", "credits" or "license" for more information.
>>> import time
>>> print time.clock()
0.0
>>> print time.clock()
0.01
>>> print time.clock()
0.01
>>> time.clock()
0.01
>>> ^D
harper:~> python
Python 2.0 (#1, Feb 26 2001, 17:11:04) [C] on sunos5
Type "copyright", "credits" or "license" for more information.
>>> import time
>>> time.clock()
0.0
>>> print time.clock()
0.0
>>> time.clock()
0.0
>>> time.clock()
0.0
>>> ^D

#---------------------------------
[wolfson at senator wolfson]$ python
Python 2.0 (#6, May 12 2001, 14:13:18) 
[GCC 2.95.1 19990816 (release)] on linux2
Type "copyright", "credits" or "license" for more information.
>>> import time
>>> time.clock()
0.16
>>> print time.clock()
0.16
>>> time.clock
<built-in function clock>
>>> _()
0.17000000000000001
>>> time.sleep(3); time.clock()
0.17000000000000001
>>> time.clock()
0.17000000000000001
>>> 

#-----------------
[wolfson at bur-jud-175-016 docs]$ python
Python 2.2 (#1, Dec 22 2001, 14:06:34) 
[GCC 2.96 20000731 (Red Hat Linux 7.1 2.96-81)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import time
>>> time.clock()
0.059999999999999998
>>> time.clock()
0.070000000000000007
>>> time.clock()
0.070000000000000007
>>> time.sleep(2.3); time.clock()
0.070000000000000007
>>> 


-- 
BTR    
BEN WOLFSON HAS RUINED ROCK MUSIC FOR A GENERATION
 -- Crgre Jvyyneq



More information about the Python-list mailing list