#from concurrent.futures import ProcessPoolExecutor
from concurrent.futures import ThreadPoolExecutor
import time
values = range(1,9999)
def dissect1(qq):
adding = sum(list1[qq:qq+100000])
averaging = adding / len(list1[qq:qq+100000])
return adding,averaging
def dissect2(qq):
adding = sum(list2[qq:qq+100000])
averaging = adding / len(list2[qq:qq+100000])
return adding,averaging
list1 = range(0, 99999999) # Two copies to speed things up?
list2 = range(0, 99999999) # Two copies to speed things up?
if __name__ == '__main__':
result1 = []
result2 = []
tic = time.time()
with ThreadPoolExecutor(max_workers=8) as exe:
result = exe.map(dissect1,range(1,5000))
with ThreadPoolExecutor(max_workers=8) as exe:
result2 = exe.map(dissect2,range(5000,9999))
toc = time.time()
print(f'Parallel execution, completed in {toc - tic} seconds')
for v in values:
a,b = dissect1(v)
tac = time.time()
print(f'Serial execution, completed in {tac - toc} seconds')
Both parallel and serial execution resulted in about 27 seconds of run time. Why is this so?
Parallel execution, completed in 27.91899013519287 seconds
Serial execution, completed in 27.62840223312378 seconds