Ich experimentierte mit dem neuen glänzenden concurrent.futures Modul in Python 3.2 eingeführt, und ich habe festgestellt, dass fast mit identischem Code, mit dem Pool von concurrent.futures ist Weg langsamer als mit multiprocessing.Pool.ProcessPoolExecutor von concurrent.futures viel langsamer als Multiprocessing.Pool
Dies ist die Version mit Multiprocessing:
def hard_work(n):
# Real hard work here
pass
if __name__ == '__main__':
from multiprocessing import Pool, cpu_count
try:
workers = cpu_count()
except NotImplementedError:
workers = 1
pool = Pool(processes=workers)
result = pool.map(hard_work, range(100, 1000000))
Und das ist mit concurrent.futures:
def hard_work(n):
# Real hard work here
pass
if __name__ == '__main__':
from concurrent.futures import ProcessPoolExecutor, wait
from multiprocessing import cpu_count
try:
workers = cpu_count()
except NotImplementedError:
workers = 1
pool = ProcessPoolExecutor(max_workers=workers)
result = pool.map(hard_work, range(100, 1000000))
eine naive Faktorisierung Funktion von diesem Eli Bendersky article genommen Verwendung, das sind die Ergebnisse auf meinem Computer (i7, 64-Bit, Arch Linux):
[[email protected]]─[~/Development/Python/test]
└[10:31:10] $ time python pool_multiprocessing.py
real 0m10.330s
user 1m13.430s
sys 0m0.260s
[[email protected]]─[~/Development/Python/test]
└[10:31:29] $ time python pool_futures.py
real 4m3.939s
user 6m33.297s
sys 0m54.853s
Ich kann diese nicht mit dem Python-Profiler profilieren, weil ich Pickle-Fehler erhalte. Irgendwelche Ideen?
Ich liebe Ihre Namenskonvention, vor allem 'Worker' und' Hard_work': P –
Cool, innit? : P – astrojuanlu