CPP VS Python Benchmark Testing
Tags: python, cpp, testing, programming
Published: 2024-03-03 11:36:46

This post will look at benchmark tests for CPP and Python programming.

The following is a partial list of the trials that will be conducted.

## List:
1. Sorting Algorithm
2. Big Data Processing
3. Scientific Computing and Mathematical Computation
4. String Processing
5. Matrix and Vector Operations
6. Modeling and Simulation Tasks
7. Intensive Memory Usage
8. Repeated Code Execution
9. CPU Usage and Multithreading
10. Network Processing and Protocols

## Results from benchmark testing

**1. Sorting Algorithm**

**CPP**
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/su0s61jedtn3z7ezs1xc.jpg)
**Python**
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wcvdto7y6okwqd77kzj1.jpg)
**Conclusion**:
- **C++**: Faster in sorting algorithms due to higher performance and more efficient memory usage.
- **Python**: Has powerful built-in libraries for sorting but typically slower than direct implementations in C++.

**2. Big Data Processing**

**CPP**
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ghs48qgvsdzi4393yp8e.jpg)
**Python**
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1ynkuhhhcbq1ynufmhds.jpg)
**Conclusion:**
- **C++**: Faster and more efficient in processing big data.
- **Python**: Easy to use but tends to be slower in processing big data.

**3. Scientific Computing and Mathematical Computation**

**CPP**
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gryzaz2jiidmmugmhvtw.jpg)
**Python**
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6i02gtulbjqrhzget5q8.jpg)
**Conclusion:**
- **C++**: Faster in mathematical computations due to compilation to machine code and performance optimization.
- **Python**: Easy to use and has efficient libraries like NumPy, but typically slower than C++.

**4. String Processing**

**CPP**
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kvnt2lytywftkssrf9i8.jpg)
**Python**
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/70rtolsj8hrvxog4q5cy.jpg)
**Conclusion:**
- **C++**: Faster in string processing due to higher performance and more efficient memory manipulation.
- **Python**: Easy to use and fast in string processing.

**5. Matrix and Vector Operations**

**CPP**
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/q0bqbsrpxrc67m02cfkk.jpg)
**Python**
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fljl7xw0yu0kp54wodff.jpg)
**Conclusion:**
- **C++**: Faster in matrix and vector operations due to higher performance and more efficient memory usage.
- **Python**: Has efficient libraries like NumPy, but typically slower than C++ in matrix and vector operations.

**6. Modeling and Simulation Tasks**

**CPP**
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jjg9l3p55m2yhugmkwqv.jpg)
**Python**
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/z2dsym8f5hc9nwwn2iq2.jpg)
**Conclusion:**
- **C++**: Faster in modeling and simulation due to higher performance and more efficient memory usage.
- **Python**: Easy to use but may be slower in modeling and simulation.

**7. Intensive Memory Usage**

**CPP**
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xd8h1tjbjvvesbeseug2.jpg)
**Python**
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xze3oq25n4ge8dkjpuke.jpg)
**Conclusion:**
- **C++**: Better in intensive memory usage due to manual memory management and greater control.
- **Python**: Easy to use but may experience larger memory overhead.

**8. Repeated Code Execution**

**CPP**
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/32vmggw0unekrsp27x9w.jpg)
**Python**
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/l5amwmqr57u1308o7sia.jpg)
**Conclusion:**
- **C++**: Faster in repeated code execution due to higher performance.
- **Python**: Slower in repeated code execution due to code interpretation and automatic memory management.

**9. CPU Usage and Multithreading**

**CPP**
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/200v42zmkhgeli7geaeq.jpg)
**Python**
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/a9xjz5tofq2mck64sild.jpg)
**Conclusion:**
- **C++**: Better in CPU usage and multithreading due to higher performance and better control over thread management.
- **Python**: Has GIL limiting multithreading but still can use multiprocessing.

**10. Network Processing and Protocols**

**CPP**
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lve1x2l3gdhm7rixg3y0.jpg)
**Python**
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qoceinxeqj8emc1a1uzj.jpg)
**Conclusion:**
- **C++**: Faster in network processing and protocols due to higher performance and better control over network management.
- **Python**: Easy to use but may be slower in network processing and protocols.

All benchmark testing has shown that CPP outperforms Python.

All Source Code Here: [:link:](https://github.com/itsukitatsuya11/CPPvsPython)