This article mainly introduces Python based on the time module to find the program runtime of the method, involving the use of the Python timing module and numerical operations related operation skills, the need for friends can refer to the next
The example in this paper describes how Python is based on the time module to find the program runtime. Share to everyone for your reference, as follows:
This timestamp is easy to log when the program's run time can take advantage of the number of milliseconds in the Unix system, from 1970.1.1 to the present.
The method is the beginning of the program to save a variable once, after the end of the program is taken to save a variable, and the start of the program to subtract the time stamp can be obtained.
The way to take this timestamp in Python is to use it when the time class is introduced time.time(); . That's in Java System.currentTimeMillis() .
As Python asks for the exact time of the current few months and days, it needs to be like Java, which can refer to Python's method of producing a unique number using the current time and random number.
The method is as follows, taking a 100,000,000, 100 million cycles of 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+=1time_end=time.time (); #time. Time () The number of milliseconds from 1970.1.1 to the current print Time_end-time_start,print "s"
The results of the operation are as follows:
The result of Time_end-time_start subtraction is a fraction of a second unit.
So the final output is then mended with a unit, s, seconds.