-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest2.py
47 lines (39 loc) · 837 Bytes
/
test2.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
# -*- coding: utf-8 -*-
import time
import numpy as np
import multiprocessing as mp
y = list(np.arange(1, 77777))
def fun(x):
global y
if x in y:
result = True
else:
result = False
return result
check_list = list(
np.arange(1, 20000)
)
if __name__=='__main__':
print(1)
# 方法1:map
time1 = time.time()
A = list(map(fun, check_list))
# 方法2:for循环
time2 = time.time()
B = []
for check_str in check_list:
if check_str in y:
B.append(True)
else:
B.append(False)
# 方法3:map+多进程
time3 = time.time()
pool = mp.Pool()
C = list(
pool.map(fun, check_list)
)
time4 = time.time()
cost1 = time2-time1
cost2 = time3-time2
cost3 = time4-time3
print(cost1,cost2,cost3)