Python Time Clock () method

Source: Internet
Author: User

Describe

The Python Time Clock () function returns the current CPU times as a number of seconds in floating-point count. It is more useful than time.time () to measure the time spent on different programs.

It is important to note that the meanings are different on different systems. On a UNIX system, it returns "process time", which is a floating-point number (timestamp) in seconds. In Windows, the first call returns the actual time that the process is running. The second subsequent call is the elapsed time since the first call to the present . (actually based on QueryPerformanceCounter () on WIN32, which is more accurate than milliseconds)

Grammar

Clock () method syntax:

Time.  Clock()  
return value

The function has two functions,

At the time of the first call, the actual time of the program running is returned;

After the second call, the time interval from the first call to the call is returned

Under the Win32 system, this function returns the real time (wall times), while the CPU time is returned under Unix/linux.

Instance

The following example shows how the clock () function is used:

ImportTimeDefProcedure():Time.Sleep(2.5)# Measure Process TimeT0=Time.Clock()Procedure()print Time. ()  - T0  "seconds process time" # measure wall time< Span class= "PLN" >t0 = Time. () procedure ()  Time. ()  - T0  "seconds Wall time"           

The result of the above example output is:

0.0 seconds Process time2.50023603439 seconds Wall   time

Python Time Clock () method

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.