YouTip LogoYouTip

Att Time Clock

# Python2.x Python time clock() Method * * * ## Description The clock() method was removed in Python 3.8. You can use the **time.perf_counter()** or **time.process_time()** methods as alternatives. The Python time clock() function returns the current CPU time in seconds as a floating-point number. It is used to measure the execution time of different programs and is more useful than time.time(). Note that its meaning varies on different systems. On UNIX systems, it returns "process time", which is a floating-point number (timestamp) in seconds. On Windows, the first call returns the actual running time of the process. Subsequent calls return the time elapsed since the first call. (It is based on QueryPerformanceCounter() on Win32, which is more precise than millisecond representation.) ## Syntax The syntax for the clock() method is: time.clock() ## Parameters * NA. ## Return Value This function has two functionalities: On the first call, it returns the actual running time of the program; On subsequent calls after the second, it returns the time interval from the first call to the current call. On win32 systems, this function returns the wall time, while on Unix/Linux it returns the CPU time. ## Example The following example demonstrates the usage of the clock() function: ## Example #!/usr/bin/python import time def procedure(): time.sleep(2.5) # measure process time t0 =time.clock() procedure() print time.clock() - t0,"seconds process time" # measure wall time t0 =time.time() procedure() print time.time() - t0,"seconds wall time" The output of the above example is: 3.3e-05 seconds process time 2.50329995155 seconds wall time
← Att Time CtimeAtt Time Asctime β†’