Re:Do you know how much your computer can do in a second?
by andreasvc on Sunday October 25, 2015 @11:11AM
(#10447065)
Nitpick: that creates a list, not an array. It could be faster, but it's not the same benchmark. When you get to the point where the speed of loops matters it's better to reach for Cython, Numba, PyPy, etc.
Re:Do you know how much your computer can do in a second?
by dalke on Sunday October 25, 2015 @07:10PM
(#10448845)
Why wonder when you can test?
% python -mtimeit '[x for x in xrange(1000)]'
10000 loops, best of 3: 70.2 usec per loop
% python -mtimeit 'for x in xrange(1000): pass'
10000 loops, best of 3: 29 usec per loop
% python -mtimeit '[x for x in xrange(100000)]'
100 loops, best of 3: 7.03 msec per loop
% python -mtimeit 'for x in xrange(100000): pass'
100 loops, best of 3: 2.5 msec per loop
Didn't find the original talk but found this: https://wiki.python.org/moin/PythonSpeed/PerformanceTips#Loo...