Example Analysis of python timestamp Subtraction
This article mainly shows you the "python timestamp subtraction example analysis", the content is simple and easy to understand, clear organization, I hope to help you solve doubts, let Xiaobian lead you to study and learn "python timestamp subtraction example analysis" this article bar.
Time stamp subtraction
Record a time point before and after code execution, and subtract the two time stamps to calculate the running time of the program.
Get timestamp time.time()
import timestart_time = time.time()sum = 0for i in range(100000000): sum += iprint(sum)end_time = time.time()print("elapsed time: {:.2f} sec.".format(end_time - start_time)) Output: 4999995000000 elapsed time: 10.53 sec.
Get the current date datetime.datetime.now ()
import datetimestart_time = datetime.datetime.now()sum = 0for i in range(100000000): sum += iprint(sum)end_time = datetime.datetime.now ()print("Time: {} seconds".format(end_time - start_time)) Above is "Python timestamp subtraction example analysis" All the contents of this article, thank you for reading! I believe that everyone has a certain understanding, hope to share the content to help everyone, if you still want to learn more knowledge, welcome to pay attention to the industry information channel!