在此代码中
t1 = os.time()
do_something_slow()
t2 = os.time()
elapsed_diff = os.difftime(t2, t1)
elapsed_sub = t2 - t1
什么情况下elapsed_diff
会与elapsed_sub
不同?
最佳答案
在非Posix系统中,不能保证os.time
返回的值可以直接相减。
In the GNU C Library, you can simply subtract time_t values. But on other systems, the time_t data type might use some other encoding where subtraction doesn't work directly. [1]
关于datetime - os.difftime(t2, t1) 的用途是什么,但 t2 - t1 未涵盖?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24585840/