[John Arbash Meine]
So 'for x in s: break' is about 2x faster than next(iter(s)) and 3x
faster than (iter(s).next()).

The first version uses direct calls for the for-loop opcodes.
The other two have to do functions/method look-up and
make a pure python function call (neither is very fast).

FWIW, a "choose" method had been previously proposed,
discussed and rejected.

I don't find the optimization issue to be very interesting in
the case of retrieving an arbitrary element.  This isn't
the kind of thing that typically appears in an inner-loop;
afterall, if you've retrieved an arbitrary element without
removing it, then successive calls to "choose" could
potentially retrieve the exact same element again and again.


Raymond
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to