Kristján Valur Jónsson wrote:
Bringing this in from python-dev, and http://bugs.python.org/issue10278
Summary: time.clock() means two different things on Windows and Unix. So, if you need to measure time across a blocking call in a portable way, you need to use time.time() (this fact is not documented). Time.time has its own problems though, such as low resolution (compared to time.clock on windows) and being susceptible to being adjusted by the user.
I proposed adding a time.wallclock() to address this issue, which would be the most suitable function for the job on any platform. The patch is an example implementation. Any thoughts? And yes, I acknowledge that the time module is complicated enough as it is :)
I'm not particularly keen on "wall_clock" as a name. The name suggests it should return something like "12:37:15". I prefer a name that tells you what you would use the function for: this is the right function to use for timers, so call it "timer".
The timeit module includes:
if sys.platform == "win32": # On Windows, the best timer is time.clock() default_timer = time.clock else: # On most other platforms the best timer is time.time() default_timer = time.time
(Aside: what about WinCE? Shouldn't it also use time.clock?)
and the timeit.Timer class takes an argument "timer" which defaults to default_timer, so there is precedent on the name.
+1 on a platform-dependent alias to time() or clock() +1 on calling it "timer" -0 on calling it "wall_clock"