Advertisement
vpao

Pool Multiprocessing

Mar 21st, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.41 KB | None | 0 0
  1. from multiprocessing import Pool
  2. import time
  3. import os
  4.  
  5. def f(n):
  6. sum = 0
  7. for x in range(1000):
  8. sum+= x*x
  9.  
  10. return sum
  11.  
  12. if __name__ == '__main__':
  13. t1 = time.time()
  14. p = Pool()
  15. result = p.map(f, range(10))
  16. p.close()
  17. p.join()
  18.  
  19. print('Pool Took : ' + time.time()-t1)
  20.  
  21. t2 = time.time()
  22. result = []
  23. for x in range(10000):
  24. result.append(f(x))
  25.  
  26. print('Serial Prcess : ' + time.time()-t2)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement