Why is time.clock giving a greater elapsed time than time.time?

Active3 hr before
Viewed126 times

4 Answers


But why/when would the processor clock give an elapsed time so much greater than the system time does?,I timed a section of python code on Ubuntu using time.clock and time.time:, About ,To learn more, see our tips on writing great answers.

I timed a section of python code on Ubuntu using time.clock and time.time:

clock elapsed time: 8.770 s
time elapsed time: 1.869 s
load more v

Running the same program under Windows gives back completely different results:,Here is an example of running time.time and time.clock on a Unix machine:,time.time() shows that the wall-clock time has passed approximately one second while time.clock() shows the CPU time spent on the current process is less than 1 microsecond. time.clock() has a much higher precision than time.time().,If garbage collection should be enabled to measure the program's performance more accurately, i.e., when the program allocates and de-allocates lots of objects, then you should enable it during the setup:

Another important concept is the so-called system time, which is measured by the system clock. System time represents a computer system's notion of the passing of time. One should remember that the system clock could be modified by the operating system, thus modifying the system time.

Python's time module provides various time-related functions. Since most of the time functions call platform-specific C library functions with the same name, the semantics of these functions are platform-dependent.

load more v

time.perf_counter() function in Python,time.process_time() function in Python,pref_counter_ns(): It always gives the integer value of time in nanoseconds. Similar to perf_counter(), but return time as nanoseconds.Code #2: Usage of the perf_counter_ns and how to implement it.  ,Polynomial Time Approximation Scheme


sys: the operating system CPU time due to system calls from the process.,user: the process CPU time.,real: the wall clock time.,In this case the wall clock time was higher than the CPU time, so that suggests the process spent a bunch of time waiting (58ms or so), rather than doing computation the whole time. What was it waiting for? Probably it was waiting for a network response from the DNS server at my ISP.

$ host - t MX pythonspeed.com
pythonspeed.com mail is handled by in2 - smtp.messagingengine.com.
pythonspeed.com mail is handled by in1 - smtp.messagingengine.com.
load more v

Other "undefined-undefined" queries related to "Why is time.clock giving a greater elapsed time than time.time?"