(8)测试多线程并发执行网络密集操作所需时间
  <code class="python">t = time.time()
  ios = []
  t = time.time()
  for x in range(10):
  thread = Thread(target=http_request)
  ios.append(thread)
  thread.start()
  e = ios.__len__()
  while True:
  for th in ios:
  if not th.is_alive():
  e -= 1
  if e <= 0:
  break
  print("Thread Http Request", time.time() - t)</code>
  Output: 0.7419998645782471、0.3839998245239258、0.3900001049041748
  (9)测试多进程并发执行CPU密集操作所需时间
  <code class="python">counts = []
  t = time.time()
  for x in range(10):
  process = Process(target=count, args=(1,1))
  counts.append(process)
  process.start()
  e = counts.__len__()
  while True:
  for th in counts:
  if not th.is_alive():
  e -= 1
  if e <= 0:
  break
  print("Multiprocess cpu", time.time() - t)</code>
  Output: 54.342000007629395、53.437999963760376
  (10)测试多进程并发执行IO密集型操作
  <code class="python">t = time.time()
  ios = []
  t = time.time()
  for x in range(10):
  process = Process(target=io)
  ios.append(process)
  process.start()
  e = ios.__len__()
  while True:
  for th in ios:
  if not th.is_alive():
  e -= 1
  if e <= 0:
  break
  print("Multiprocess IO", time.time() - t)</code>
  Output: 12.509000062942505、13.059000015258789
  (11)测试多进程并发执行Http请求密集型操作
  <code class="python">t = time.time()
  httprs = []
  t = time.time()
  for x in range(10):
  process = Process(target=http_request)
  ios.append(process)
  process.start()
  e = httprs.__len__()
  while True:
  for th in httprs:
  if not th.is_alive():
  e -= 1
  if e <= 0:
  break
  print("Multiprocess Http Request", time.time() - t)</code>
  Output: 0.5329999923706055、0.4760000705718994
  实验结果 CPU密集型操作 IO密集型操作 网络请求密集型操作 线性操作 94.91824996469 22.46199995279 7.3296000004 多线程操作 101.1700000762 24.8605000973 0.5053332647 多进程操作 53.8899999857 12.7840000391 0.5045000315
  通过上面的结果,我们可以看到:
  多线程在IO密集型的操作下似乎也没有很大的优势(也许IO操作的任务再繁重一些能体现出优势),在CPU密集型的操作下明显地比单线程线性执行性能更差,但是对于网络请求这种忙等阻塞线程的操作,多线程的优势便非常显著了
  多进程无论是在CPU密集型还是IO密集型以及网络请求密集型(经常发生线程阻塞的操作)中,都能体现出性能的优势。不过在类似网络请求密集型的操作上,与多线程相差无几,但却更占用CPU等资源,所以对于这种情况下,我们可以选择多线程来执行