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.
We're a place where coders share, stay up-to-date and grow their careers.
We strive for transparency and don't collect excess data.