Does Python allow access to some of the implementation details?

"Martin v. Löwis" martin at v.loewis.de
Sat Jan 7 08:52:46 EST 2006


Claudio Grondi wrote:
>> You can get somewhat faster in Python than your code if you avoid
>> producing new long objects all the time, and do the task in chunks of 30
>> bits.
> 
> It would be nice if you could explain why you consider chunks of 30 bits
> to be superior e.g. to chunks of 32 bits?

With chunks of 32 bits, you might get negative numbers. Then,
right-shifting bit-by-bit will never get you to zero.

It also happens that the long ints are represented as arrays of
15-bit values, so that the shift by 30 *could* be implemented
without shifts in the individual words; however, this optimization
is not done.

Regards,
Martin



More information about the Python-list mailing list