Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Example Analysis of python timestamp Subtraction

2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report