Python3.5 vs 3.7进程时间
我只在iMac(macOS Mojave,版本10.14.3)上看到这个问题。我的Windows和Linux(CentOS)计算机没有这样的问题。iMac的人能证实这一点吗 进程时间当我使用适用于Mac OS的最新Python 3.7版本运行时,在单线程程序中,时间(CPU时间)是性能计数器(挂钟)的两倍: $python3.7 test.py Python(“v3.7.2:9a3ffc0492”,“2018年12月24日02:44:43”)Clang6.0(Clang600.0.57) CPU时间:15.92581399999999挂钟:7.970086342距离:750 我认为Python 3.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时间:8.09766挂钟:8.108357406000323距离:750 这是Python3.7中的一个bug,还是我对进程时间不太了解 下面是我运行“test.py”的代码:Python3.5 vs 3.7进程时间,python,macos,time,process,Python,Macos,Time,Process,我只在iMac(macOS Mojave,版本10.14.3)上看到这个问题。我的Windows和Linux(CentOS)计算机没有这样的问题。iMac的人能证实这一点吗 进程时间当我使用适用于Mac OS的最新Python 3.7版本运行时,在单线程程序中,时间(CPU时间)是性能计数器(挂钟)的两倍: $python3.7 test.py Python(“v3.7.2:9a3ffc0492”,“2018年12月24日02:44:43”)Clang6.0(Clang600.0.57) CPU
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)
这里的代码是的,这是macOS的Python 3.7和3.8二进制发行版中的错误,下载:
$python3.8 test.py
Python版本:3.8.0a2
构建:('v3.8.0a2:23f4589b4b','2019年2月25日10:59:08')
编译器:Clang 6.0(Clang-600.0.57)
CPU时间:16.005979999997挂钟:8.014987319距离:750
我从gitHub获得源代码,使用最新的编译器在Mac上编译,问题消失了:
$。/python.exe test.py
Python版本:3.8.0a2+
建造:('heads/master:a9df651eb4','2019年3月5日17:21:48')
编译器:Clang 10.0.0(Clang-1000.11.45.5)
CPU时间:7.21238700000005挂钟:7.21903976距离:750
稍微修改了“test.py”程序以正确报告Python版本:
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 version :", platform.python_version())
print(" build :", platform.python_build())
print(" compiler:", 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)
这个bug是在3.7.0中引入的一个回归,每当Python构建在macOS 10.11或更早版本上时都会看到。修复程序现在可用,将在Python 3.7.5和3.8.0b4中发布。有关更多详细信息,请参阅。