Python implements a simple timer function

Source: Internet
Author: User
The examples in this article describe Python's implementation of a simple timer function. Share to everyone for your reference. Specific as follows:

This function implements a simple timer kinetic energy through Python:

"Simple Timing function.this Function prints out a message with the elapsed time from theprevious call. It works with the most Python 2.x platforms. The functionuses a simple trick to store a persistent variable (clock) withoutusing a global variable. Import Timedef dur (Op=none, Clock=[time.time ()]): if op! = None:duration = Time.time ()-clock[0] print '%s fini Shed.  Duration%.6f seconds. '% (OP, Duration) clock[0] = Time.time () # ExampleIf __name__ = = ' __main__ ': Import array dur ()   # initialise The timing clock opt1 = Array.array (' H ') for I in range (£): for-N in range: Opt1.append (n) Dur (' Array from append ') Opt2 = Array.array (' H ') seq = range ($) for I in Range (): Opt2.extend (seq) dur (' Ar Ray from list extend ') Opt3 = Array.array (' h ') seq = Array.array (' h ', range (+)) for I in range (£): Opt3.extend (seq) dur (' array from array extend ') # output:# array from append finished. Duration 0.175320 seconds.# Array from list extend finiShed. Duration 0.068974 seconds.# array from array extend finished. Duration 0.001394 seconds.

Hopefully this article will help you with Python programming.

  • 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.