Python3.7中time模块的time()、perf_counter()和process_time()的区别(转)
原文:https://blog.csdn.net/qq_27283619/article/details/89280974
timeit官方文档
- time()精度上相对没有那么高,而且受系统的影响,适合表示日期时间或者大程序程序的计时。
- perf_counter()适合小一点的程序测试,
会计算sleep()时间
。 - process_counter()适合小一点的程序测试,
不会计算sleep()时间
。
此外Python3.7开始还提供了以上三个方法精确到纳秒的计时。分别是:time.perf_counter_ns()
time.process_time_ns()
time.time_ns()
注意这三个精确到纳秒的方法返回的是整数类型。 - 以前还有一个clock()方法,尽管现在这个方法还能用,但是这个方法在Python3.8中会被废除掉了,所以这里就不过多介绍。