$ python -m timeit -r 1000 -s "bla=[1,2,3]" "for item in bla:" " item" 1000000 loops, best of 1000: 0.306 usec per loop
$ python -m timeit -r 1000 -s "bla=[1,2,3]" "lista=bla.__iter__()" "while True:" " try:" " lista.next()" " except:" " break" 100000 loops, best of 1000: 3.13 usec per loop
__iter__ + try..except + while is round 11x slower than “for in” loop.
0 comments ↓
There are no comments yet...Kick things off by filling out the form below.
Leave a Comment