I am testing python's multiprocessing module with the following code:
from multiprocessing import Pool
import math
def f(x):
for i in range(1,1000):
y = (x*x)/math.sqrt(i)
return y
if __name__ == '__main__':
p = Pool(7)
print(p.map(f, range(20000)))
This gives me a time of around 39.8s with 7 cores. I verified all 7 processors were being worked on task manager.
The single core implementation:
print [f(x) for x in range(20000)]
takes 38s to complete. My understanding is that this is a very CPU intensive task so the 7-core version should be faster than the single core. Why am I not seeing any improvement in performance (infact seeing a decrease)