Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 过程、时间和现实的差异_Python_Python 3.x_Time_Process - Fatal编程技术网

Python 过程、时间和现实的差异

Python 过程、时间和现实的差异,python,python-3.x,time,process,Python,Python 3.x,Time,Process,我正在测量函数的处理时间,但打印的结果不正确。实际上,时间要少得多(约5小时),但输出显示需要15小时。从进程时间的文档中,它应该打印小数秒 import time start = time.process_time() main() #function to calculate the elapsed time print ("time took: ") print(time.process_time() - start) 有人能告诉我这里可能出了什么问题吗?谢谢:)您是否尝试过使用tim

我正在测量函数的处理时间,但打印的结果不正确。实际上,时间要少得多(约5小时),但输出显示需要15小时。从进程时间的文档中,它应该打印小数秒

import time

start = time.process_time()
main() #function to calculate the elapsed time
print ("time took: ")
print(time.process_time() - start)

有人能告诉我这里可能出了什么问题吗?谢谢:)

您是否尝试过使用
time.time()
而不是
time.process\u time()
?我的意思是,假设它不是很准确,但它肯定比错误的结果要好5个小时。。。对吗?首先,根据,
time.process\u time()
返回系统CPU时间和用户CPU时间之和。此外,由于文档还声明它的定义是进程范围的,并且存在
time.thread\u time()
,因此我假设
time.process\u time()
在使用多线程时会考虑同一进程内多个线程的CPU时间。。。