2

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?

Eric
  • 95,302
  • 53
  • 242
  • 374
  • See also http://stackoverflow.com/questions/13855890/what-is-the-difference-between-difftime-and. – lhf Jul 05 '14 at 21:08

1 Answers1

4

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]

lhf
  • 70,581
  • 9
  • 108
  • 149