Skip to content

Instantly share code, notes, and snippets.

@jstrieb
Created December 29, 2018 20:25
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 jstrieb/f6714db3211cfb529f0b07e1d2c0bc38 to your computer and use it in GitHub Desktop.
Save jstrieb/f6714db3211cfb529f0b07e1d2c0bc38 to your computer and use it in GitHub Desktop.
Demonstration of Python multiprocessing map
import time
from multiprocessing.dummy import Pool
with Pool() as p:
start = time.time()
print("Starting fast map...", end="")
p.map(lambda _: time.sleep(.01), range(1000))
print("Took %0.2f seconds\n" % (time.time() - start))
start = time.time()
print("Starting slow map...", end="")
list(map(lambda _: time.sleep(.01), range(1000)))
print("Took %0.2f seconds\n" % (time.time() - start))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment