I am wondering why python 2.7 uses gettimeofday() when running time.time() but yet in python 3.4 it does not?
It appears when running strace that it may be querying /etc/localtime
I am wondering why python 2.7 uses gettimeofday() when running time.time() but yet in python 3.4 it does not?
It appears when running strace that it may be querying /etc/localtime
当您的系统在编译时gettimeofday()被检测到支持这一点时, Python 3 将使用它。但是,在 POSIX 系统上,它只会在不可用的情况下使用它;根据POSIX 2008 标准,后者是首选,因为它被认为已过时。clock_gettime(CLOCK_REALTIME)gettimeofday()
time.get_clock_info()在运行时,您可以使用function查询 Python 认为您的系统在编译时可以支持什么,该function返回一个namedtuple带有implementation字段的实例:
implementation : 用于获取时钟值的底层 C 函数的名称
在我的 OSX 10.11 系统上,'time'时钟产生gettimeofday():
>>> time.get_clock_info('time').implementation
'gettimeofday()'
您可以通读pygettimeofday()C 实现以查看可以使用哪些实现;例如,在 WindowsGetSystemTimeAsFileTime()上使用。