-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_await.py
51 lines (33 loc) · 1.09 KB
/
test_await.py
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
import time
from fork import *
@cpu_bound
def fib(n):
return 1 if n <= 1 else fib(n-1) + fib(n-2)
@io_bound
def webservice():
time.sleep(0.001)
return 'result'
def test_cpu_bound_await(n):
print('##### test_cpu_bound_await #####')
print(await(process(fib, n)))
def test_cpu_bound_await_all(n):
print('##### test_cpu_bound_await_all #####')
print(await_all(map_process(fib, range(n))))
def test_cpu_bound_await_any(n):
print('##### test_cpu_bound_await_any #####')
print(await_any(map_process(fib, range(n))))
def test_io_bound_await(n):
print('##### test_io_bound_await #####')
print(await(thread(webservice)))
def test_io_bound_await_all(n):
print('##### test_io_bound_await_all #####')
print(await_all([thread(webservice) for i in range(n)]))
def test_io_bound_await_any(n):
print('##### test_io_bound_await_any #####')
print(await_any([thread(webservice) for i in range(n)]))
test_cpu_bound_await(10)
test_cpu_bound_await_all(10)
test_cpu_bound_await_any(10)
test_io_bound_await(10)
test_io_bound_await_all(10)
test_io_bound_await_any(10)