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.

4
  • this is greate work cod3monk3y... thank you for sharing! Commented Apr 17, 2014 at 14:00
  • 8
    On Windows, time.clock measures elapsed time to high precision. On OS X and Linux, it measures CPU time. As of Python 3.3 it is deprecated in favor of perf_counter to measure elapsed time and process_time to measure CPU. Commented Jun 9, 2016 at 3:51
  • 5
    This answer is misleading. Just because your windows has timer resolution set to 1ms at the time you ran this script does not guarantee that another process cannot or will not set it to a higher resolution. The default resolution is 15.6ms, any process can come along and change that value. I ran your script and I got 15ms delta, then I used github.com/tebjan/TimerTool and set it to 1ms and ran it again and got 1ms time delta. Be wary of assuming that windows is holding 1ms timer resolution, you should be explicit and set it yourself at the start of your script if needed. Commented Mar 19, 2019 at 18:02
  • My latest testing shows that time.time_ns() has a precision of only 1~11 ms, whereas time.perf_counter_ns() is far superior, being about 100k times better, at 0.100 us precision. See my results for both Linux and Windows. You can run my code there to test your system for yourself. Commented Dec 16, 2024 at 22:31