![图片[1]-怎么计算python程序运行时间-uusu优素-乐高,模型,3d打印,编程](http://uusucn.zbbe.cn/wp-content/uploads/2024/01/5eaa4b90eb840939.jpg)
python脚本使用统计时间的方式是time.clock(),而这种方式统计的是CPU的执行时间,不是程序的执行时间。
下面我们就来看一下计算python程序运行时间的方法:
deftime_function(f,*args): """ Callafunctionfwithargsandreturnthetime(inseconds)thatittooktoexecute. """ importtime tic=time.time() f(*args) toc=time.time() returntoc-tic
使用time()返回程序运行时和程序结束的时间戳,然后将两个时间相减即可获得程序运行时间。
原文来自:https://www.py.cn© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END


















































暂无评论内容