Sequential vs. Parallel Processing in Python

Egemen Eroglu
2 min readJul 14, 2023

--

Efficient data retrieval is crucial for processing large datasets quickly. In this article, we compare sequential and parallel processing in Python for retrieving data from an API. We’ll examine two code implementations and highlight the benefits of parallel processing for improved speed and efficiency.

Slower Code:

As you can see it took ≥=6 min. Let’s do the same operation with parallel processing!

Faster Code:

This implementation employs parallel processing using ThreadPoolExecutor to execute multiple requests simultaneously, significantly reducing execution time.

Open your calculators we gonna do a little math here!

Slower Process = (6min. x 60 sec.) + 42 sec. ≈ 400 sec.

Faster Process = ~40sec.

Performance Improvement Rate = ((Slower Code Execution Time — Faster Code Execution Time) / Slower Code Execution Time) * 100

= ((400–40) / 400) * 100 = 90%

This means that the faster code performs the data retrieval task approximately 90% faster than the slower code.

Conclusion

Efficient data retrieval is crucial for handling large datasets. In this article, we compared sequential and parallel processing in Python for retrieving data from an API. The parallel implementation demonstrated faster execution and improved efficiency. By leveraging parallel processing, developers can enhance data retrieval performance and optimize resource utilization.

For dataset and codes, you can check here: https://www.kaggle.com/datasets/erogluegemen/tdk-turkish-words (upvotes are appreciated 😇)

--

--

Egemen Eroglu

I write articles about Data Engineering and Data Science | Data Engineer @Bosch