Skip to content

This Python script provides examples of different approaches to calculate the average of multiple lists using sequential, asynchronous, multithreading, and multiprocessing techniques.

Notifications You must be signed in to change notification settings

MarcLinderGit/Concurrent_Programming

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 

Repository files navigation

Multithreading and Multiprocessing Comparison

This Python script provides examples of different approaches to calculate the average of multiple lists using sequential, asynchronous, multithreading, and multiprocessing techniques. The script demonstrates the execution time of each approach, highlighting the benefits and trade-offs of each method.

Script Overview

The script includes the following approaches:

  1. Sequential Approach: Calculates the average of each list one after the other in a sequential manner.
  2. Async Approach: Utilizes asynchronous programming to calculate the averages concurrently using asyncio. The await asyncio.sleep(1) simulates asynchronous work.
  3. Threading Approach: Uses multithreading with Python's threading module to perform calculations concurrently in separate threads.
  4. Multiprocessing Approach: Utilizes the multiprocessing module to run separate processes for each list, achieving true parallelism on multi-core systems.

Running the Script

To run the script and compare the execution times of different approaches:

  1. Make sure you have Python installed on your system.

  2. Open a terminal or command prompt.

  3. Navigate to the directory containing the script.

  4. Run the script by executing the following command:

    python concurrent_programming.py
  5. The script will execute each approach and print the elapsed time for each one.

Results

The script will demonstrate the time taken for each approach to calculate the average of the provided lists. You will observe the differences in execution time, showcasing the benefits and considerations for each approach.

Notes

  • This script serves as an educational example to understand the concepts of sequential programming, asynchronous programming, multithreading, and multiprocessing.

  • Depending on your hardware and system configuration, you may observe different execution times for each approach.

  • The use of multithreading and multiprocessing is beneficial when dealing with computationally intensive tasks that can be parallelized, but it also comes with additional complexities and considerations, such as data sharing and synchronization.

  • Asynchronous programming is useful for I/O-bound tasks where waiting for external resources is the primary bottleneck.

  • The choice of the best approach depends on the specific requirements of your application and the type of tasks you need to perform concurrently.

Enjoy exploring and comparing different concurrent programming approaches with this script!

About

This Python script provides examples of different approaches to calculate the average of multiple lists using sequential, asynchronous, multithreading, and multiprocessing techniques.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages