C++ vs. Python Empirical Runtime Analysis
Measuring the performance differences in C++ and Python for various Data Structures and Algorithms
Empirically testing the runtime characteristics of C++
and Python
.
Python
is an interpreted language, and the interpreter is running the same code over and over again. The C++
code is compiled to machine code, and thus runs much faster & is optimized to reduce superfluous calculations/repetitive tasks.
Build
Each implementation runs n
operations of a combination of k
data structure & algorithm implementations, all wrapped in a CPU profiler. The results are written to a .prof
file that is then profiled externally (Using my psuedo-profiler
tool for assistance).
The algorithms selected are common data structures & algorithms that are widely used in practice and have well-understood theoretical time and space complexity, serving as excellent benchmarks.
The complete code is available on GitHub.
Runtime Performance
As expected, the Python
performance is exponentially slower than the equivalent C++
implementation in the number of operations.
The complete code is available on GitHub.