2015-01-12 30 views
0

timeit源,我有(Python 2.7版)有爲什麼python timeit檢查win32而不是win *?

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 

然而,文件表明,所有Windows機器的行爲相同

在默認的定時器功能不同的是,因爲在Windows上, 時鐘()具有微秒的粒度,但時間()的粒度是1/60第一個第 ...

發生了什麼o n 64位Windows?在64位Windows上,time.time實際上更好嗎?

回答

3

看來,甚至64位窗口會告訴你,它的平臺是「win32」。我是一個64位Windows 7系統上,這裏是我所看到的:

>>> import sys 
>>> sys.platform 
'win32' 

因此,64位的Windows也將使用time.clock

+1

另外請注意,顯然stdlib沒有遵循自己的建議在這裏... ['sys.platform'](https://docs.python.org/2/library/sys.html#sys 。平臺)使用'str.startswith' ... :-) – mgilson

+0

@mgilson:'startswith'被推薦支持Linux 2.x和3.x(Python 3只使用''linux'')。 Windows總是「win32」。 – jfs

相關問題