4

So I am using time.time() in my python module to track execution time and act as a while loop escape upon timeout.

My question is when does time.time() rollover/overflow. Or does it? I don't fully comprehend python datatypes yet, so I am not sure how far it can keep increasing.

Wilsonator
  • 407
  • 1
  • 5
  • 14
  • related: [Get the highest possible `gmtime()` for any architecture](http://stackoverflow.com/q/32045725/4279) – jfs Feb 27 '16 at 17:19
  • related: [How does python's time.time() method work?](http://stackoverflow.com/q/27830403/4279) – jfs Feb 27 '16 at 17:21
  • related: [Latest possible FILETIME](http://stackoverflow.com/q/9999393/4279) – jfs Feb 27 '16 at 17:35

2 Answers2

2

It will be a while. time.time() returns the time in seconds since the epoch as a float. On UNIX machines the epoch is usually 1970-1-1. IIRC, the epoch on windows is 1601-1-1.

According to sys.float_info:

In [2]: sys.float_info
Out[2]: sys.float_info(max=1.7976931348623157e+308, max_exp=1024, max_10_exp=308, min=2.2250738585072014e-308, min_exp=-1021, min_10_exp=-307, dig=15, mant_dig=53, epsilon=2.220446049250313e-16, radix=2, rounds=1)

So we have

In [3]: 1.7976931348623157e+308/(3600*24*365.0)
Out[3]: 5.700447535712569e+300

years before rollover. :-)

Roland Smith
  • 42,427
  • 3
  • 64
  • 94
  • Good to hear! If this project is still going years from now, I have bigger problems. Thanks! – Wilsonator Mar 31 '13 at 19:46
  • 1- the epoch for `time.time()` is still `1970` even on Windows (check `time.gmtime(0).year`). The [underlying implementation](http://stackoverflow.com/q/27830403/4279) does uses 1601 and 100 nanoseconds ticks returned by `GetSystemTimeAsFileTime()` but it is not visible from Python (python sees "seconds since Epoch" value). 2- [Valid timestamps (`time_t`) are far less than `sys.float_info.max`](http://stackoverflow.com/q/32045725/4279). It is as small as something like ~3000 years on Windows. Though the actual `time.time()` limit (max `FILETIME`) is less than 30828 years on Windows. – jfs Feb 27 '16 at 17:34
0

Using time.clock() would be more accurate.

  • clock() has higher precision which is not the same as accuracy – kilojoules Feb 27 '16 at 16:27
  • but precision is very similar to being exact and when you are being exact you are being accurate you are just playing with words, nothing helpful is being said. – johnAbruzzi Feb 28 '16 at 22:08
  • They are different terms - http://kaffee.50webs.com/Science/images/Accuracy-vs-precision1.jpg – kilojoules Feb 29 '16 at 00:50
  • again, seriously."The state or quality of being precise" is exactly what precision means.and when we say something is precise we say that it is accurate.these are all synonyms,perhaps different words but same meaning. – johnAbruzzi Mar 02 '16 at 17:46
  • OK. I see now that time.time() actually has more precision that time.clock(). nvm. – kilojoules Mar 02 '16 at 20:23