Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

13
  • 1
    Btw, it crashes on Darwin for now. Commented Sep 9, 2016 at 19:43
  • 1
    I suppose that doesn't surprise me; low-level timing relies heavily on the inner workings of the operating system, and Darwin is neither Linux nor Windows based. If you can get something similar, with similar resolution, working on Darwin too let me know and I can incorporate it into my code. Commented Sep 10, 2016 at 1:01
  • > On my Windows machine, it's resolution is perhaps 8ms at best, whereas my module above has 0.5us resolution (16000 times better!) on the same machine. -- 8ms or .8ms in time module and 0.5us or 50 us in GS module? Commented Apr 30, 2022 at 9:41
  • 1
    @brec, what version of Python are you using? In modern Python 3, import time followed by time.monotonic_ns() might be sufficient. At the time of my answer, that didn't exist. See docs.python.org/3/library/time.html#time.monotonic_ns. This is new in Python 3.7. I haven't tested it myself yet though. Thanks for @HenrikMadsen for posting this in his answer here, which he since deleted, unfortunately. Commented Aug 24, 2022 at 2:29
  • 1
    Gabriel, I'm using 3.10.5. And after my previous comment I used time.perf_counter_ns -- which, on MacOS, is the same as time.monotonic_ns. But I had thought I was using something not as accurate as your code. Thanks for the info! Commented Aug 25, 2022 at 3:16