-
-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathtest17.py
More file actions
79 lines (61 loc) · 1.4 KB
/
test17.py
File metadata and controls
79 lines (61 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import time
start = time.time()
def sync_fnc():
for i in range(10):
time.sleep(0.5)
print(i)
sync_fnc()
end = time.time()
print(end - start)
import asyncio
import time
start = time.time()
async def myFnc():
for i in range(10):
await asyncio.sleep(0.5) # 이벤트루프를 블락하지 않음
print(i)
loop = asyncio.get_event_loop()
loop.run_until_complete(myFnc())
loop.close()
end = time.time()
print(end - start)
import time
start = time.time()
def sync_fnc():
for i in range(10):
time.sleep(0.5)
print(i)
sync_fnc()
sync_fnc()
sync_fnc()
end = time.time()
print(end - start)
import asyncio
import time
start = time.time()
async def myFnc():
for i in range(10):
await asyncio.sleep(0.5) # 이벤트루프를 블락하지 않음
print(i)
loop = asyncio.get_event_loop()
loop.run_until_complete(asyncio.gather(myFnc(), myFnc(), myFnc()))
loop.close()
end = time.time()
print(end - start)
import asyncio
import time
start = time.time()
async def myFnc():
for i in range(10):
await asyncio.sleep(0.5) # 이벤트루프를 블락하지 않음
print(i)
return "Test"
loop = asyncio.get_event_loop()
dd = asyncio.ensure_future(myFnc())
loop.run_until_complete(asyncio.gather(
dd, asyncio.ensure_future(myFnc()), asyncio.ensure_future(myFnc())
))
loop.close()
end = time.time()
print(end - start)
print(dd.result())