Is there a way to measure time with high-precision in Python — more precise than one second? I doubt that there is a cross-platform way of doing that; I’m interesting in high precision time on Unix, particularly Solaris running on a Sun SPARC machine.
timeit seems to be capable of high-precision time measurement, but rather than measure how long a code snippet takes, I’d like to directly access the time values.
The standard
time.time()function provides sub-second precision, though that precision varies by platform. For Linux and Mac precision is+-1 microsecond or 0.001 milliseconds. Python on Windows with Python < 3.7 uses+-16 milliseconds precision due to clock implementation problems due to process interrupts. Thetimeitmodule can provide higher resolution if you’re measuring execution time.Python 3.7 introduces new functions to the
timemodule that provide higher resolution for longer time periods: