TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Ask HN: Do you need to work at a ns precision?

5 pointsby scared2almost 5 years ago
I just saw that python datetime 64 default setting is at a ns scale. I just wonder how many people actually need that setting.

2 comments

mytailorisrichalmost 5 years ago
Most CPUs run at &gt; 1GHz these days so 1ns is already not precise enough to count cycles, but is small enough that it will be fine for the vast majority of use cases. If you need picosecond accuracy you are probably doing something that requires special hardware anyway.<p>These other aspect is that 64 bits allow such a huge interval that it makes sense to use it. Even counting in nanoseconds increments this allows for a monotonic counter to run over literally hundreds of years.<p>So 64 bits in increments of 1ns (or close to) is both doable on most modern hardware and allows for the vast majority of use cases for decades to come (if not longer) without have to think about changing it again and again.
easytigeralmost 5 years ago
Worked for many years measuring and instrumenting systems at the nanosecond levels on Linux.<p>Windows is generally not considered viable for work at that level. Other Unix I&#x27;ve not used in that fashion sadly.<p>The python datetimes just wrap Linux calls to clock_gettime() to populate a timespec. On 32bit that is a syscall but on 64bit it is a VDSO, thus costs mostly just a memory access and avoids stack swap. (so very fast)<p>If you are using it to measure anything reliably you need a fairly solid ptp time infrastructure or it is pointless