Created
June 17, 2019 08:25
This file contains hidden or 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