Is there enough time in Python time.time () * 1000?

I want to write timestamps to the second second in python. It looks like the standard answer is int(time.time() * 1000)

However, if time.time() returns a float, would there be a problem with precision? There will be some values ​​that will not exactly display as float.

I'm worried about some fractional moments that do not display correctly as a float, and the timestamp in these cases jumps forward or backward.

Is this a serious problem?

If so, what is the workaround?

+4
source share
1 answer

How much accuracy do you want? Although it is true that there are finite decimal fractions that cannot be represented as finite binary fractions, the closest approximate value is rounded to the correct number of whole milliseconds if you do not synchronize a program that has been running for 143 millennia (2 ** 52 milliseconds).

In short: I don't think you need to worry about floating point precision. You may need to worry about system timer accuracy, accuracy, or monotony.

+3
source

Source: https://habr.com/ru/post/1444702/


All Articles