散尽浮华 2023

過去心不可得,現在心不可得,未來心不可得。
安寻安放,不卑不亢;重剑无锋,大巧不工!
  1. 首页
  2. python
  3. 正文

统计代码段执行时间的方法

2022年3月23日 1162点热度 5人点赞 0条评论

方法(1)

import time


start_s=time.perf_counter()
time.sleep(5)
end_s = time.perf_counter()

exec_ms = (end_s - start_s)*1000
print('消耗 %.2f 毫秒。' % exec_ms)

方法(2)

import urllib3
from timeit import default_timer as timer


http = urllib3.PoolManager(num_pools=100, headers={'Connection': 'keep-alive'}, maxsize=100, block=True)

url = "https://www.yjsec.com"

tic = timer()
resp = http.request('GET', url)
toc = timer() - tic
print('消耗了 %0.2f 毫秒' % (toc * 1000))

print(resp.status)
print(resp.headers['Date'])
标签: 暂无
最后更新:2022年3月23日

admin

这个人很懒,什么都没留下

点赞
< 上一篇
下一篇 >

文章评论

razz evil exclaim smile redface biggrin eek confused idea lol mad twisted rolleyes wink cool arrow neutral cry mrgreen drooling persevering
取消回复

COPYRIGHT © 2023 散尽浮华 2023. ALL RIGHTS RESERVED.

Theme Kratos Made By Seaton Jiang