标签:使用 调用 lap splay 爬虫 总结 process col 虚拟
1 import time
2 from multiprocessing import Process
3 from threading import Thread
4
5 # def func():
6 # num = 0
7 # for i in range(1,100000000):
8 # num += i
9
10 def func():
11 time.sleep(2)
12 print(‘xxxxxxxx‘)
13
14 if __name__ == ‘__main__‘:
15 p_s_t = time.time()
16 p_list = []
17 for i in range(10):
18 p = Process(target=func,)
19 p_list.append(p)
20 p.start()
21 [pp.join() for pp in p_list]
22 p_e_t = time.time()
23 p_dif_t = p_e_t - p_s_t
24
25 t_s_t = time.time()
26 t_list = []
27 for i in range(10):
28 t = Thread(target=func,)
29 t_list.append(t)
30 t.start()
31 [tt.join() for tt in t_list]
32 t_e_t = time.time()
33 t_dif_t = t_e_t - t_s_t
34
35 print(‘多进程执行的时间‘,p_dif_t)
36 print(‘多线程执行的时间‘,t_dif_t)
标签:使用 调用 lap splay 爬虫 总结 process col 虚拟
原文地址:https://www.cnblogs.com/hq82/p/9876087.html