Follow the documentation Python (ii): Comparison and summary of Time.time () and Time.clock ()

Source: Internet
Author: User

One, two functions of the document:

1,time.time ():

time. Time ( )

Return the time in seconds since the epoch as a floating point Number. Note that even though the time was always returned as a floating point number, not all systems provide time with a better p Recision than 1 second. While this function normally returns non-decreasing values, it can return a lower value than a previous call if the system Clock has been set back between the calls.

—————————————————————————————————————————————

time. Time ( )

Returns the number of seconds since the era (1970.1.1). Although the return value of this function is always a floating-point number, not all system-supplied seconds will be accurate after the decimal point. In general, the return value of this function is not less than the return value it was called last time, unless the system clock resets between two calls.

2,time.clock ():

Time . Clock ( )

On Unix, return the current processor time as a floating point number expressed in seconds. The precision, and in fact the very definition of the meaning of "processor Time", depends on that of the C function of th E same name, but in any case, the "the function to use for benchmarking Python or timing algorithms."

On Windows, this function returns wall-clock seconds elapsed since the first call to this function, as a floating point nu Mber, based on the Win32 function QueryPerformanceCounter (). The resolution is typically better than one microsecond.

 
   

—————————————————————————————————————————————

Time . Clock ( )

In Unix, the current processor time is returned in the form of a floating-point number in seconds. Its accuracy (accurately, "Processor Time" accuracy) depends on the C function of the same name, which, in any case, is a python ruler for time calculations.

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)

Two, usage and summary
1, in Windows, Time.clock () more accurate;
2, these two functions can not be mixed use;

(not to be continued)

Reference: Python Time Clock () method | Beginner's Tutorial

Follow the documentation Python (ii): Comparison and summary of Time.time () and Time.clock ()

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.