[Python-ideas] Add time.time_ns(): system clock with nanosecond resolution
Victor Stinner
victor.stinner at gmail.com
Sun Oct 15 05:59:57 EDT 2017
> Might it make more sense to have a parallel *module* that works with a
different base data type rather than parallel functions within the existing
API?
I asked about adding new functions to 4 different modules: os, resource,
signal, time.
For example, I dislike the idea of having os and os_ns modules. We already
have os.stat() which returns time as seconds and nanoseconds (both at the
same time). There is also os.utime() which accepts time as seconds *or*
nanoseconds: os.utime (path, times=seconds) or os.utime(path,
ns=nanoseconds).
If we had a time_ns module, would it only contain 4 clocks or does it have
to duplicate the full API? If yes, it is likely to be a mess to maintain
them. How will user choose between time and time_ns? What if tomorrow
clocks get picosecond resolution? (CPU TSC also has sub-nanosecond
resolution, but OS API uses timespec, 1 ns res.) Add a third module?
I prefer to leave all "time functions" in the "time module".
For example, I don't think that we need to add time.nanosleep() or
time.sleep_ns(), since the precision loss starts after a sleep of 104 days.
Who cares of 1 nanosecond after a sleep of 104 days?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20171015/5101c5a4/attachment.html>
More information about the Python-ideas
mailing list