In this code
t1 = os.time()
do_something_slow()
t2 = os.time()
elapsed_diff = os.difftime(t2, t1)
elapsed_sub = t2 - t1
Under what circumstances will elapsed_diff
be different to elapsed_sub
?
In this code
t1 = os.time()
do_something_slow()
t2 = os.time()
elapsed_diff = os.difftime(t2, t1)
elapsed_sub = t2 - t1
Under what circumstances will elapsed_diff
be different to elapsed_sub
?
In non-Posix systems, there is no guarantee that the values returned by os.time
can be subtracted directly.
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]