python 异步编程 asyncio
2021-02-14 13:17
标签:datetime loop localtime for let 异步 cio async mba python 异步编程 asyncio 标签:datetime loop localtime for let 异步 cio async mba 原文地址:https://www.cnblogs.com/wuzaipei/p/12722978.htmlimport datetime
import time
import asyncio
import numba as nb
import numpy as np
@nb.jit()
def f(n):
if n:
return 1
else:
return f(n-1)+f(n-2)
async def fun(m):
asyncio.sleep(0.1)
return ‘输出{}‘.format(i)
loop = asyncio.get_event_loop()
st = time.time()
for i in range(41000):
s = loop.run_until_complete(fun(i))
# print(s,‘ ‘,time.strftime(‘%Y-%m-%d %H:%M:%S‘,time.localtime()))
st2 = time.time()
print(‘异步编程用时:‘,st2-st,‘ s‘)
def fun2(m):
time.sleep(0.1)
return ‘输出{}‘.format(i)
for i in range(41):
s = fun2(i)
# print(s, ‘ ‘, time.time())
print(‘同步编程用时:‘,time.time()-st2,‘ s‘)
文章标题:python 异步编程 asyncio
文章链接:http://soscw.com/index.php/essay/55212.html