【发布时间】:2022-09-13 19:37:45
【问题描述】:
为了加速测试一段代码,在 Python 中比较 2 次的正确方法是什么?我试着阅读 API 文档。我不确定我是否理解 timedelta 的事情。
到目前为止我有这段代码:
from datetime import datetime
tstart = datetime.now()
print t1
# code to speed test
tend = datetime.now()
print t2
# what am I missing?
# I'd like to print the time diff here
【问题讨论】:
-
为什么不打印 t2-t1?是什么阻止了你做减法?
-
猜猜,我有过“这不可能那么容易”的时刻。
标签: python datetime time time-measurement