High-precision clock in Python
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 uses +-
16 milliseconds precision due to clock implementation problems due to process interrupts. The timeit
module can provide higher resolution if you're measuring execution time.
>>> import time
>>> time.time() #return seconds from epoch
1261367718.971009
Python 3.7 introduces new functions to the time
module that provide higher resolution:
>>> import time
>>> time.time_ns()
1530228533161016309
>>> time.time_ns() / (10 ** 9) # convert to floating-point seconds
1530228544.0792289
High-precision clock in Python
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 uses +-
16 milliseconds precision due to clock implementation problems due to process interrupts. The timeit
module can provide higher resolution if you're measuring execution time.
>>> import time
>>> time.time() #return seconds from epoch
1261367718.971009
Python 3.7 introduces new functions to the time
module that provide higher resolution:
>>> import time
>>> time.time_ns()
1530228533161016309
>>> time.time_ns() / (10 ** 9) # convert to floating-point seconds
1530228544.0792289
Related Topics
Matplotlib: How to Plot Images Instead of Points
Comprehension for Flattening a Sequence of Sequences
How to Get Flask to Run on Port 80
Unnamed Python Objects Have the Same Id
How to Convert an Array of Strings to an Array of Floats in Numpy
Special (Magic) Methods in Python
How to Get a Raw, Compiled SQL Query from a SQLalchemy Expression
How to Get 2.X-Like Sorting Behaviour in Python 3.X
Why Aren't Superclass _Init_ Methods Automatically Invoked
Getting Rid of Console Output When Freezing Python Programs Using Pyinstaller
How to Get Item's Position in a List
Serialize Python Dictionary to Xml
Python Read from Subprocess Stdout and Stderr Separately While Preserving Order
How to Plot Nan Values as a Special Color with Imshow in Matplotlib
Make a Post Request While Redirecting in Flask
Implement Matlab's Im2Col 'Sliding' in Python
Typeerror: Unsupported Operand Type(S) for /: 'Str' and 'Str'