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.