With the Time module in python is it possible to measure elapsed time? If so, how do I do that?
I need to do this so that if the cursor has been in a widget for a c
For the best measure of elapsed time (since Python 3.3), use time.perf_counter().
Return the value (in fractional seconds) of a performance counter, i.e. a clock with the highest available resolution to measure a short duration. It does include time elapsed during sleep and is system-wide. The reference point of the returned value is undefined, so that only the difference between the results of consecutive calls is valid.
For measurements on the order of hours/days, you don't care about sub-second resolution so use time.monotonic() instead.
Return the value (in fractional seconds) of a monotonic clock, i.e. a clock that cannot go backwards. The clock is not affected by system clock updates. The reference point of the returned value is undefined, so that only the difference between the results of consecutive calls is valid.
In many implementations, these may actually be the same thing.
Before 3.3, you're stuck with time.clock().
On Unix, return the current processor time as a floating point number expressed in seconds. The precision, and in fact the very definition of the meaning of “processor time”, depends on that of the C function of the same name.
On Windows, this function returns wall-clock seconds elapsed since the first call to this function, as a floating point number, based on the Win32 function QueryPerformanceCounter(). The resolution is typically better than one microsecond.
New in Python 3.7 is PEP 564 -- Add new time functions with nanosecond resolution.
Use of these can further eliminate rounding and floating-point errors, especially if you're measuring very short periods, or your application (or Windows machine) is long-running.
Resolution starts breaking down on perf_counter() after around 100 days. So for example after a year of uptime, the shortest interval (greater than 0) it can measure will be bigger than when it started.
time.clock is now gone.