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


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.

Updated on: 30-Jul-2019

392 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements