Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # rgb_multiprocessing_test.py
- import multiprocessing as mp
- from random import randint as rnd
- import time
- def my_function(i, param1, param2, param3):
- result = []
- for z in range(800):
- result += [tuple(rnd(0,255) for rgb in 'rgb')]
- return (result)
- def get_result(result):
- results.extend(result)
- if __name__ == '__main__':
- params = [[[0,0,0] for i in range(1200)] for i in range(800)]
- results = []
- ts = time.time()
- for i in range(0, len(params[0])):
- get_result(my_function(i, params[0][i], params[1][i], params[2][i]))
- print('Time in serial:', time.time() - ts)
- #print(results)
- results = []
- ts = time.time()
- pool = mp.Pool(mp.cpu_count())
- for i in range(0, len(params[0])):
- pool.apply_async(my_function, args=(i, params[0][i], params[1][i], params[2][i]), callback=get_result)
- pool.close()
- pool.join()
- print('Time in parallel:', time.time() - ts)
- #print(results)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement