[Python-3000] range() issues
Nick Coghlan
ncoghlan at gmail.com
Thu May 1 16:41:57 CEST 2008
Martin v. Löwis wrote:
>> In the slow example given, only one of the returned items needs to be a
>> long
>
> This is Py3k. They are all longs.
Not inside the object they aren't - I believe the optimised one uses C
longs internally, and converts to a Python long when it returns the
values, whereas 'longrange' uses Python long objects internally as well.
Oddly enough, this is going to make the increment/decrement operations
for the counter quite a bit slower :)
One way to optimise this (since all we need to support here is counting
rather than arbitrary arithmetic) would be for the longrange iterator to
use some simple pure C fixed point arithmetic internally to keep track
of an arbitrarily long counter, and only convert to a Python long when
it has to (just like the optimised shortrange iterator).
I'm not sure it is worth the hassle though.
Cheers,
Nick.
--
Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia
---------------------------------------------------------------
http://www.boredomandlaziness.org
More information about the Python-3000
mailing list