Python Calculation program Run time

Source: Internet
Author: User

Python calculates the run time of the program, which first needs to be imported.

About the time module:

Serial Number Functions and descriptions Example
1 Time.altzone
Returns the number of seconds to offset the daylight saving time region in West Greenwich. If the region returns negative values in eastern Greenwich (such as Western Europe, including the UK). Available for daylight saving time enabled regions.
>>>Import time>>>print("Time.altzone%d"% time. ) Altzone)time.  -28800              
2 Time.asctime ([Tupletime])
Accepts a time tuple and returns a read-only string of 24 characters in the form "Tue Dec 11 18:07:14 2008" (December 11, 2008 Tuesday 18:07 14 seconds).
>>> ImportTime>>>T=Time.LocalTime()>>> print Span class= "pun" > ( "Time.asctime (t):%s"  % Time. Asctime (ttime.< Span class= "PLN" >asctime (t  apr 710:36:20  2016             
3 Time.clock ()
The number of seconds used to calculate the floating-point count returns the current CPU time. It is more useful than time.time () to measure the time spent on different programs.
4 Time.ctime ([secs])
function equivalent to Asctime (localtime (secs)), parameter is not given equal to Asctime ()
>>> import Time>>>  print  ( "Time.ctime (): %s " % Time. () time. ()  : thu  apr 710:51:58  2016             
5 Time.gmtime ([secs])
Receives the time suffix (the number of floating-point seconds elapsed after the 1970 era) and returns the time-tuple T in Greenwich Astronomical time. Note: T.TM_ISDST is always 0
>>> ImportTime>>> Print ("Gmtime:",Time.Gmtime(1455508609.34375))Gmtime:Time.Struct_time(Tm_year=2016, Tm_mon=2, Tm_mday=15  
Tm_hour=3,< Span class= "PLN" > Tm_min=56, Tm_sec=49, Tm_wday= 0, Tm_yday=46 , Tm_isdst=0)
6 Time.localtime ([secs]
The Receive time suffix (the number of floating-point seconds after the 1970 era) and the time-of-day tuple T (t.tm_isdst 0 or 1, depending on whether the local time is daylight saving).
>>> ImportTime>>> Print ("LocalTime ():",Time.LocalTime(1455508609.34375))LocalTime():Time.Struct_time(Tm_year=2016, Tm_mon=2, Tm_mday=15 , 
Tm_hour=11,< Span class= "PLN" > Tm_min=56, Tm_sec=49, Tm_wday= 0, Tm_yday=46 , Tm_isdst=0)
7 Time.mktime (Tupletime)
Accepts the time tuple and returns the time suffix (the number of floating-point seconds elapsed after the 1970 era).
8 Time.sleep (secs)
Postpone the call thread's run, secs refers to the number of seconds.
#!/usr/bin/python3import  Timeprint  ( "Start:%s"  % Time. () time. ( 5 ) print  ( "End:%s"  % Time. ()               
9 Time.strftime (Fmt[,tupletime])
Receives a time tuple and returns the local time as a readable string, formatted as determined by the FMT.
>>>  import Time>>>  print  (time strftime ( "%y-%m-%d%h:%m:%s"  Time. ()) 2016-04 -07 11: 18:05          
10 Time.strptime (str,fmt= '%a%b%d%h:%m:%s%Y ')
Resolves a time string to a time tuple according to the format of the FMT.
>>> ImportTime>>>Struct_time=Time.Strptime("00", "%d%b%y")>>> Print ("Return tuple:",Struct_time)Returns a tuple:Time.Struct_time(Tm_year=2000, Tm_mon=11, Tm_mday=30 , 
Tm_hour=0, Tm_min=0, tm_sec =0, Tm_wday= 3, Tm_yday=335, Tm_isdst=-1)
11 Time.time ()
Returns the timestamp of the current time (the number of floating-point seconds elapsed after the 1970 era).
>>>Import time>>>print(time.  Time())1459999336.1963577         
12 Time.tzset ()
Re-initializes time-related settings according to the environment variable TZ.

Calculate Program Run Time:

Method ①:

Python Calculation program Run time

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.