python2以及python3的通用计时办法(保举学习:Python视频教程)
因为python2以及3外面的计时函数是纷歧样的,倡议应用timeit模块中的timeit.default_timer()
由timeit.default_timer()的民间文档可知,计不时间精度战争台和应用的函数无关:
“界说正在默许的计时器中,针对没有同平台采纳没有同形式。正在Windows上,time.clock()具备微秒精度,然而time.time()精度是1/60s。正在Unix上,time.clock()有1/100s精度,并且time.time()精度远远更高。正在另外的平台上,default_timer()丈量的是墙上时钟工夫,没有是CPU工夫。这象征着同一较量争论机的其余过程可能影响计时。”
python2中:
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
python3中:
default_timer = time.perf_counter
再由time.clock()的民间文档能够看出:
“python3.3版本后time.clock()就过期了:这个函数的行为受平台影响,用time.perf_counter()”或许time.process_time()替代来失去一个界说更好的行为,详细取决于你的需要。”
更多Python相干技巧文章,请拜访Python教程栏目进行学习!
以上就是python若何计时的具体内容,更多请存眷资源魔其它相干文章!
标签: Python python教程 python编程 python使用问题
抱歉,评论功能暂时关闭!