码迷,mamicode.com
首页 > 编程语言 > 详细

python 异步编程 asyncio

时间:2020-04-17 23:33:18      阅读:83      评论:0      收藏:0      [点我收藏+]

标签:datetime   loop   localtime   for   let   异步   cio   async   mba   

import datetime
import time
import asyncio
import numba as nb
import numpy as np

@nb.jit()
def f(n):
    if n<2:
        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

标签:datetime   loop   localtime   for   let   异步   cio   async   mba   

原文地址:https://www.cnblogs.com/wuzaipei/p/12722978.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!