Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vincenzomanzoni/eec971bff2fe206dc3ec2894c19ca11e to your computer and use it in GitHub Desktop.
Save vincenzomanzoni/eec971bff2fe206dc3ec2894c19ca11e to your computer and use it in GitHub Desktop.
Playing with Python Multiprocessing
import multiprocessing
import time
from multiprocessing import Pool
def f(x):
return x**2
print("Number of CPUs available: ", multiprocessing.cpu_count())
print("Start parallel computation")
start = time.clock()
with Pool() as p:
l = p.map(f, range(0, 10000000))
end = time.clock()
print("End parallel computation: %.2gs" % (end - start))
print("Start sequential computation")
start = time.clock()
list(map(f, range(0, 10000000)))
end = time.clock()
print("End parallel computation: %.2gs" % (end - start))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment