Python __iter__ performance

$ 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.

Share and Enjoy:
  • Google Bookmarks
  • Twitter
  • BLIP - Bardzo Lubię Informować Przyjaciół
  • pinger.pl - Nie taki zwykły blog.
  • Facebook
  • del.icio.us
  • Digg
  • Wrzuć to na Flakera - powiadom swoich Znajomych
  • grono.net - internetowa społeczność przyjaciół
  • Netvibes
  • LinkedIn
  • Technorati
  • Dodaj niusa « OSnews.pl

0 comments ↓

There are no comments yet...Kick things off by filling out the form below.

Leave a Comment