[Python-Dev] PEP 410 (Decimal timestamp): the implementation is ready for a review (original) (raw)

Victor Stinner victor.stinner at gmail.com
Wed Feb 15 18:23:55 CET 2012


2012/2/15 Guido van Rossum <guido at python.org>:

I just came to this thread. Having read the good arguments on both sides, I keep wondering why anybody would care about nanosecond precision in timestamps.

Python 3.3 exposes C functions that return timespec structure. This structure contains a timestamp with a resolution of 1 nanosecond, whereas the timeval structure has only a resolution of 1 microsecond. Examples of C functions -> Python functions:

If we keep float, Python would have has worse precision than C just because it uses an inappropriate type (C uses two integers in timeval).

Linux supports nanosecond timestamps since Linux 2.6, Windows supports 100 ns resolution since Windows 2000 or maybe before. It doesn't mean that Windows system clock is accurate: in practical, it's hard to get something better than 1 ms :-) But you may use QueryPerformanceCounter() is you need a bettre precision, it is used by time.clock() for example.

For measuring e.g. file access times, there is no way that the actual time is know with anything like that precision (even if it is recorded as a number of milliseconds -- that's a different issue).

If you need a real world example, here is an extract of http://en.wikipedia.org/wiki/Ext4:

"Improved timestamps As computers become faster in general and as Linux becomes used more for mission-critical applications, the granularity of second-based timestamps becomes insufficient. To solve this, ext4 provides timestamps measured in nanoseconds. (...)"

So nanosecond resolution is needed to check if a file is newer than another. Such test is common in build programs like make or scons.

Filesystems resolution:

Victor



More information about the Python-Dev mailing list