Created
December 29, 2018 20:25
-
-
Save jstrieb/f6714db3211cfb529f0b07e1d2c0bc38 to your computer and use it in GitHub Desktop.
Demonstration of Python multiprocessing map
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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