python3.7和3.5_Python3.5与3.7进程

我只在iMac上看到这个问题(MacOSMojave,10.14.3版)。我的Windows和Linux(CentOS)计算机没有这个问题。iMac的人能确认一下吗?在

当我使用最新的适用于Mac OS的Python 3.7版本运行时,在单线程程序中,进程时间时间(CPU时间)比性能计数器大两倍:$ python3.7 test.py

Python ('v3.7.2:9a3ffc0492', 'Dec 24 2018 02:44:43') Clang 6.0 (clang-600.0.57)

CPU time: 15.925813999999999 Wall clock: 7.970086342 Distance: 750

我看不出Python3.5有同样的问题:$ python3.5 test.py

Python ('v3.5.1:37a07cee5969', 'Dec 5 2015 21:12:44') GCC 4.2.1 (Apple Inc. build 5666) (dot 3)

CPU time: 8.09766 Wall clock: 8.108357406000323 Distance: 750

是Python3.7中的一个bug,还是我对进程时间有些不理解?在

这是我运行的代码'测试.py':import time

import sys

import platform

def distance(a, b):

if a == b:

return 0

d = sys.maxsize

for i, c in enumerate(a):

d = min(d, ord(c) + distance(a[:i]+a[i+1:], b))

for i, c in enumerate(b):

d = min(d, ord(c) + distance(a, b[:i]+b[i+1:]))

return d

print("Python", platform.python_build(), platform.python_compiler())

cpu = time.process_time()

clock = time.perf_counter()

d = distance("12345", "abcde")

clock = time.perf_counter() - clock

cpu = time.process_time() - cpu

print("CPU Time:", cpu, "Wall Clock:", clock, " Distance:", d)

代码在这里

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值