【问题标题】:Why does python timeit check for win32 instead of win*?为什么 python timeit 会检查 win32 而不是 win*?
【发布时间】:2015-01-12 15:56:12
【问题描述】:

我拥有的timeit 源(python 2.7)有

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 上, clock() 的粒度是微秒,但 time() 的粒度是 1/60 一秒钟……

在 64 位 Windows 上会发生什么? time.time 在 64 位 Windows 上真的更好吗?

【问题讨论】:

    标签: python windows time 64-bit


    【解决方案1】:

    似乎即使是 64 位窗口也会告诉您它的平台是“win32”。我在 64 位 Windows 7 系统上,我看到的是:

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

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

    【讨论】:

    • 另请注意,显然 stdlib 在这里没有遵循自己的建议...sys.platform 上的建议是使用str.startswith... :-)
    • @mgilson: startswith 建议同时支持 Linux 2.x 和 3.x(Python 3 仅使用 'linux')。 Windows 始终为'win32'
    猜你喜欢
    • 1970-01-01
    • 2011-05-08
    • 2012-06-15
    • 2017-01-06
    • 2019-03-10
    • 2018-01-04
    • 2013-01-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多