Use of the clock () method for processing time in Python, pythonclock

Source: Internet
Author: User

Use of the clock () method for processing time in Python, pythonclock

The clock () method returns the current processor time, in seconds representing a floating point number on Unix. The accuracy depends on the C function with the same name, but in any case, this is an algorithm function that is used for benchmarking Python or timing.

In Windows, this function is returned because the first call of this function has been suspended for several seconds. As a floating point number, it is based on the Win32 function QueryPerformanceCounter.
Syntax

The following is the syntax of the clock () method:

Time. clock ()

Parameters

  • NA

Return Value

This method returns the current processor time as a floating point number in UNIX seconds, and in Windows it indicates that the first call to this function is called in the past clock second, as a floating point number.
Example

The following example shows how to use the clock () method.

#! /Usr/bin/pythonimport timedef procedure (): time. sleep (2.5) # measure process timet0 = time. clock () procedure () print time. clock ()-t0, "seconds process time" # measure wall timet0 = time. time () procedure () print time. time ()-t0, "seconds wall time"

When we run the above program, it will produce the following results:

0.0 seconds process time2.50023603439 seconds wall time

Note: not all systems can measure the actual processing time. In such a system (including Windows), because of the start time of the program.

Related Article

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.