Comparative analysis of code execution time by C and Python based on selected algorithms
Abstract
The article deals with a comparative analysis of the speed of code execution written in the C language and Python. In order to determine whether a scripting language can match the performance of a compiled language, a comparison of the languages was made using the following algorithms: the algorithm for solving the Hanoi tower problem, the Huffman encoding algorithm and the algorithm for converting numbers into text. Each of the listed algorithms was implemented in both languages. Then the execution time of the programs was measured and the results were obtained, which prove that the C language achieves better performance in most cases.
Keywords
performance; algorithms; C; Python
References
Analysis of C++ and Python in Terms of Memory and Time, Preprints (2020), https://doi.org/10.20944/preprints202012.0516.v1.
L. Prechelt, An empirical comparison of seven programming languages, Computer 33 (10) (2000) 23-29, https://doi.org/10.1109/2.876288.
H. Zhang, J. Nie, Program Performance Test based on Different Computing Environment, 2016 IEEE International Conference of Online Analysis and Computing Science (ICOACS) (2016) 174-177.
J. -J. Merelo-Guervós et al., A comparison of implementations of basic evolutionary algorithm operations in different languages, 2016 IEEE Congress on Evolutionary Computation (CEC) (2016) 1602-1609.
V. M. Ionescu, F. M. Enescu, Investigating the performance of MicroPython and C on ESP32 and STM32 microcontrollers, 2020 IEEE 26th International Symposium for Design and Technology in Electronic Packaging (SIITME) (2020) 234-237.
Sposób pomiaru czasu wykonania programu w języku C, https://levelup.gitconnected.com/8-ways-to-measure-execution-time-in-c-c-48634458d0f9 , [01.02.2022].
Opis wyrażenia makro CLOCKS_PER_SEC, https://www.educative.io/answers/what-is-clockspersec-in-c , [25.09.2022].
Sposób pomiaru czasu wykonania programu w języku Python, https://pynative.com/python-get-execution-time-of-program/ , [01.02.2022].
Opis problemu dotyczącego algorytmu rozwiązującego problem wieży Hanoi, https://pl.wikipedia.org/wiki/Wie%C5%BCe_Hanoi , [01.02.2022].
Kod algorytmu rozwiązującego problem wieży Hanoi w języku C oraz Python, https://www.geeksforgeeks.org/c-program-for-tower-of-hanoi/ , [03.04.2022].
Opis przebiegu algorytmu kodowania Huffmana, https://binarnie.pl/kodowanie-huffmana/ , [01.02.2022].
Kod algorytmu kodowania Huffmana w języku C oraz Python, https://www.programiz.com/dsa/huffman-coding , [03.04.2022].
Kod algorytmu kodowania Huffmana w języku C oraz Python, https://www.techiedelight.com/huffman-coding/ , [03.04.2022].
Poland

This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.