What is the difference between time.clock() and time.time()?

MCAOperating SystemUnix

The function time.time() returns the time in seconds since the epoch, i.e., the point where the time starts.

For Unix, the epoch is January 1, 1970. For Windows, the epoch is January 1, 1601.

time.time() is used for benchmarking on Windows. time.time() behaves the same on both UNIX and Windows but time.clock() has different meanings.

On UNIX, time.clock returns the current processor time expressed in seconds, i.e., the CPU time it takes to execute the current thread so far. While on Windows, it returns the wall-clock time expressed in seconds elapsed since the first call to this function, based on the Win32 function QueryPerformanceCounter().

Note that time.time() could return a value smaller than a previous call to time.time(), if the system clock has been set back between the two calls. time.clock always return non-decreasing values.

Published on 08-Jan-2018 10:42:00