How to return the current CPU time in Python?

PythonServer Side ProgrammingProgramming

To get the timer ticks at a given time, use the time.time() function. It returns the time in seconds since the epoch as a floating point number. Note that even though the time is always returned as a floating point number, not all systems provide time with a better precision than 1 second. 


import time
curr_time = time.time()



Note that different systems will have different accuracy based on their internal clock setup (ticks per second). but it's generally at least under 20ms. Also note while this function normally returns non-decreasing values, it can return a lower value than a previous call if the system clock has been set back between the two calls.

Published on 08-Jan-2018 10:36:45