How can I retrieve wall-time in Python using the standard library?
This question, and this question would suggest that something like clock_gettime(CLOCK_MONOTONIC_RAW)
or /proc/uptime
are most appropriate on Linux. On Windows, time.clock()
has the desired effect.
I would use time.time()
, but the function is not guaranteed to return monotonically (and linearly) increasing time values.
Time module in Python provides various time-related functions. This module comes under Python’s standard utility modules. time.time () method of Time module is used to get the time in seconds since epoch. The handling of leap seconds is platform dependent. Note: The epoch is the point where the time starts, and is platform dependent.
The Python time module provides various time-related functions, such as getting the current time and suspending the calling thread’s execution for the given number of seconds. The below steps show how to use the time module to calculate the program’s execution time.
The Python Standard Library ¶. The library contains built-in modules (written in C) that provide access to system functionality such as file I/O that would otherwise be inaccessible to Python programmers, as well as modules written in Python that provide standardized solutions for many problems that occur in everyday programming.
Python’s standard library is very extensive, offering a wide range of facilities as indicated by the long table of contents listed below. The library contains built-in modules (written in C) that provide access to system functionality such as file I/O that would otherwise be inaccessible to Python programmers,...
Victor Stinner wrote a Python implementation of a monotonic timer. See http://bugs.python.org/issue10278 for the discussion and the docs for the upcoming 3.3 release referencing the new feature (coded in C).
There is also Monoclock:
Monoclock is a Python module that provides access to the monotonic clock on POSIX-like OSes that have
librt
.Compatibility: tested on CPython 2.6.5, CPython 2.7, pypy 1.3, and pypy 1.4.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With