davidgaf

mp

May 22nd, 2018
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.46 KB | None | 0 0
  1. #!/usr/bin/env python
  2. from multiprocessing import Pool
  3. import time
  4.  
  5. def f(x):
  6.     return x*x
  7.  
  8. def loop():
  9.     plist = []
  10.     for i in [1,2,3]:
  11.         plist.append(i*i)
  12.     print(plist)
  13.  
  14. if __name__ == '__main__':
  15.     p = Pool(3)
  16.     start_time = time.time()
  17.     print(p.map(f, [1,2,3]))
  18.     end_time = time.time() - start_time
  19.     print(end_time)
  20.     start_time = time.time()
  21.     loop()
  22.     end_time = time.time() - start_time
  23.     print(end_time)
Add Comment
Please, Sign In to add comment