Advertisement
Guest User

Untitled

a guest
Oct 21st, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. import time
  2.  
  3. import numpy as np
  4. from multiprocessing import Process
  5.  
  6.  
  7. mem = []
  8.  
  9. def sum_(arr):
  10. mem.append(sum(arr))
  11.  
  12. class timer:
  13. def __enter__(self):
  14. self.start = time.clock()
  15.  
  16. def __exit__(self, type, value, traceback):
  17. print(time.clock() - self.start)
  18.  
  19.  
  20. if __name__ == '__main__':
  21. with timer() as t:
  22. time.sleep(10)
  23.  
  24.  
  25. def donothing():
  26. mem.clear()
  27. N = 7
  28. with timer() as t:
  29. arr = np.linspace(0, 1, 10 ** N)
  30. wp = []
  31.  
  32. with timer() as t:
  33. for i in range(2):
  34. p = Process(target=sum_, args=(arr[i*5*10**(N-1): (i+1)*5*10**(N-1)],))
  35. p.start()
  36. wp.append(p)
  37. for i in wp:
  38. i.join()
  39. mem.clear()
  40. with timer() as t:
  41. sum_(arr)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement