Created
June 17, 2019 08:25
-
-
Save thomo/53c0c1db5938a80b5fe68631cfa99633 to your computer and use it in GitHub Desktop.
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 collections | |
import multiprocessing | |
import time | |
startzeit = time.time() | |
Scientist = collections.namedtuple('Scientist', [ | |
'name', | |
'born', | |
]) | |
scientists = ( | |
Scientist(name='Ada Lovelace', born=1815), | |
Scientist(name='Emmy Noether', born=1882), | |
Scientist(name='Marie Curie', born=1867), | |
Scientist(name='Tu Youyou', born=1930), | |
Scientist(name='Ada Yonath', born=1939), | |
Scientist(name='Vera Rubin', born=1928), | |
Scientist(name='Sally Ride', born=1951), | |
) | |
def process_item(item): | |
return { # same line | |
'name': item.name, | |
'age': 2017 - item.born | |
} | |
if __name__ == '__main__': # only in main | |
pool = multiprocessing.Pool() # number of worker processes depends on CPU | |
result = pool.map(process_item, scientists) | |
print(tuple(result)) | |
endzeit = time.time() | |
diff = endzeit - startzeit | |
print("Zeit:" + str(diff)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment