This repository contains code to compare the running time of different methods for iterating over a loop in Python. The methods tested include regular loop, parallel processing, built-in functions, NumPy, PyTorch, pandas, and TensorFlow.
Loops are a fundamental concept in programming, and the efficiency of iterating over a loop can have a significant impact on the performance of a program. In Python, there are various methods for iterating over a loop, each with its own advantages and disadvantages in terms of performance.
- Regular Loop: Traditional sequential iteration using a for loop.
- Parallel Processing: Utilizing parallel processing to distribute the workload across multiple CPU cores.
- Built-in Functions: Utilizing built-in functions such as
map()
orfilter()
for iteration. - NumPy: Utilizing NumPy arrays for vectorized operations.
- PyTorch: Utilizing PyTorch tensors for tensor-based operations.
- Pandas: Utilizing pandas DataFrame for data manipulation and iteration.
- TensorFlow: Utilizing TensorFlow tensors for tensor-based operations.
To run the performance comparison tests, follow these steps:
-
Clone this repository:
git clone https://github.com/your_username/python-loop-performance.git
-
Install the required dependencies:
pip install pandas numpy torch tensorflow
This will execute the performance comparison tests for each method and display the results.
The results of the performance comparison tests will be displayed, showing the execution time for each method. Additionally, the results may vary depending on the input size and complexity of the loop operation.
Contributions are welcome! If you have suggestions for additional loop iteration methods to test or improvements to the existing code, feel free to open an issue or submit a pull request.
This project is licensed under the MIT License - see the LICENSE file for details.