Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import time
- import numpy as np
- from multiprocessing import Process
- mem = []
- def sum_(arr):
- mem.append(sum(arr))
- class timer:
- def __enter__(self):
- self.start = time.clock()
- def __exit__(self, type, value, traceback):
- print(time.clock() - self.start)
- if __name__ == '__main__':
- with timer() as t:
- time.sleep(10)
- def donothing():
- mem.clear()
- N = 7
- with timer() as t:
- arr = np.linspace(0, 1, 10 ** N)
- wp = []
- with timer() as t:
- for i in range(2):
- p = Process(target=sum_, args=(arr[i*5*10**(N-1): (i+1)*5*10**(N-1)],))
- p.start()
- wp.append(p)
- for i in wp:
- i.join()
- mem.clear()
- with timer() as t:
- sum_(arr)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement