CO
connor-mccarthy/parallelism-with-python
๐ Multithreading, multiprocessing, execution pools, asyncio, and Cython.
I went exploring parallelism in Python.
Below are some comparisons benchmarking performance of different parallel programming approaches for solving arbitrary I/O and compute tasks. The tasks vary between approaches (i.e. between async/await and multiprocessing) and are not directly comparable.
Results:
Async await
Slower approach: Finished 'no_async' in 5.0055s
Faster approach: Finished 'yes_async' in 1.0057s
Speed improvement 4.98x
Multiprocessing
Slower approach: Finished 'no_multiprocessing' in 2.1139s
Faster approach: Finished 'yes_multiprocessing' in 0.1232s
Speed improvement 17.16x
Multiprocessing with execution pools
Slower approach: Finished 'no_multiprocessing' in 2.1328s
Faster approach: Finished 'yes_multiprocessing' in 0.1227s
Speed improvement 17.39x
Threading
Slower approach: Finished 'no_threading' in 4.0146s
Faster approach: Finished 'yes_threading' in 1.0011s
Speed improvement 4.01x
Threading with execution pools
Slower approach: Finished 'no_threading_execution_pool' in 4.0097s
Faster approach: Finished 'yes_threading_execution_pool' in 1.0066s
Speed improvement 3.98x
Note: The speed improvement multipliers will typically be even larger for larger amounts of work, as the "spin-up" time of each approach will make up a smaller fraction of the total work/waiting time. This is a blunt benchmark.
To reproduce:
python -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
python src/demos/main.pyOn this page
Languages
Python100.0%
Created June 15, 2021
Updated March 8, 2023