time.time or time.clock

Fredrik Lundh fredrik at pythonware.com
Mon Jan 14 14:30:15 EST 2008


dwblas at gmail.com wrote:
> """
> <snipped>
> time.clock() isn't high enough resolution for Ubuntu,   and time.time()
> isn't > high enough resolution on windows.
> 
> Take a look at datetime.  It is good to the micro-second on Linux and
> milli-second on Windows.

datetime.datetime.now() does the same thing as time.time(); it uses the 
gettimeofday() API for platforms that have it (and so does time.time()), 
and calls the fallback implementation in time.time() if gettimeofdat() 
isn't supported.  from the datetime sources:

#ifdef HAVE_GETTIMEOFDAY
	struct timeval t;
#ifdef GETTIMEOFDAY_NO_TZ
	gettimeofday(&t);
#else
	gettimeofday(&t, (struct timezone *)NULL);
#endif
         ...
#else	/* ! HAVE_GETTIMEOFDAY */

	/* No flavor of gettimeofday exists on this platform.  Python's
	 * time.time() does a lot of other platform tricks to get the
	 * best time it can on the platform, and we're not going to do
	 * better than that (if we could, the better code would belong
	 * in time.time()!)  We're limited by the precision of a double,
	 * though.
	 */

(note the "if we could" part).

</F>




More information about the Python-list mailing list