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.

3

2 Answers 2

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. :-)

Sign up to request clarification or add additional context in comments.

2 Comments

Good to hear! If this project is still going years from now, I have bigger problems. Thanks!
1- the epoch for time.time() is still 1970 even on Windows (check time.gmtime(0).year). The underlying implementation 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. 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.
0

Using time.clock() would be more accurate.

5 Comments

clock() has higher precision which is not the same as accuracy
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.
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.
OK. I see now that time.time() actually has more precision that time.clock(). nvm.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.