Loops in Python – comparison, and performance

Duomly on October 24, 2019

Python is one of the most popular programming languages today. It’s an interpreted and high-level language with elegant and readable syntax. Howeve... [Read Full]
markdown guide

Not really measuring loop performance. The while and for loops are measuring 'append' performance, and the numpy loop fails to include the overhead of constructing the numpy arrays, and getting the results out again.

That said, interesting article, certainly illustrates the idea.


Append is too slow, must compare allocating the full list before the loop


Do the times for numpy take into account the time required to copy the Python data to the numpy object? If not, what are the results that way?


Numpy code you tried is vectorized so it runs faster. You could also try cython or numba to check the improvement in execution time.

code of conduct - report abuse