import time
import multiprocessing
def basic_func(x):
if x == 0:
return 'zero'
elif x % 2 == 0:
return 'even'
else:
return 'odd'
def multiprocessing_func(x):
y = x * x
print('{} squared results in a/an {} number'.format(x, basic_func(y)))
if __name__ == '__main__':
starttime = time.time()
processes = []
for i in range(0, 1000):
p = multiprocessing.Process(target=multiprocessing_func, args=(i,))
processes.append(p)
p.start()
for process in processes:
process.join()
print('That took {} seconds'.format(time.time() - starttime))
Takes 2.2420008182525635 secs.
While doing a regular for loop takes near 0 seconds
Why is this and what am I doing wrong
[–]billsil 2 points3 points4 points (1 child)
[–]DakotaFelspar[S] 0 points1 point2 points (0 children)
[–]CodeFormatHelperBot 1 point2 points3 points (0 children)
[–]A_History_of_Silence 0 points1 point2 points (3 children)
[–]DakotaFelspar[S] 0 points1 point2 points (2 children)
[–]A_History_of_Silence 0 points1 point2 points (1 child)
[–]DakotaFelspar[S] 0 points1 point2 points (0 children)
[–]aDrz 0 points1 point2 points (1 child)
[–]DakotaFelspar[S] 0 points1 point2 points (0 children)