"Python" to ask for the running time of the program __python

Source: Internet
Author: User

To record the running time of the program you can take advantage of the number of milliseconds in the UNIX system for the 1970.1.1 to the present time, and this timestamp is easily completed.

The method is to save a variable at the beginning of the program, and then save a variable at the end of the program, and then subtract the timestamp from the start of the program.

Python's method of taking this timestamp is to use Time.time () after introducing the time class, which can be taken out. The System.currenttimemillis () in Java.

Since Python needs the exact time of the current few months, like Java, this constant is involved, so in "Python" using the current time, random numbers to produce a unique number (click on the Open link) is not introduced.

The specific method is as follows, taking a 100,000,000-, 100 million-cycle time as an example

Import time;
Time_start=time.time () #time. Time () is the number of milliseconds from 1970.1.1 to the current
i=0;
While i<100000000:
    i+=1
time_end=time.time (), #time. Time () is the number of milliseconds from 1970.1.1 to the current date
print Time_end-time_ Start,
print "s"

The results of the operation are as follows:


The result of Time_end-time_start subtraction is directly a fraction of a second.

So the final output is then filled with a unit, S, second.

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.