Assignment Versus Equality

BartC bc at
Wed Jun 29 05:49:06 EDT 2016

On 29/06/2016 06:26, Steven D'Aprano wrote:

> BUT in Python 3, the distinction between int and long is gone by dropping int
> and renaming long as "int". So all Python ints are BIGNUMs.
> In principle Python might use native 32 or 64 bit ints for small values and
> secretly promote them to BIGNUMs when needed, but as far as I know no
> implementation of Python currently does this.

Presumably the implementation of BIGNUMs would already do something like 
this: a number that fits into 64 bits would only use 64 bits. The 
overheads of dealing with both small BIGNUMs and big ones, or a mix, 
might be lost in the other overheads of CPython.

But I remember when playing with my tokeniser benchmarks earlier this 
year that switching from dealing with strings, to integers, didn't make 
things much faster (I think they actually made it slower sometimes).

Even if Python has extremely efficient string handling, we know that 
low-level string ops normally take longer than low-level integer ops.

So maybe small-integer handling already had enough overhead that 
implementing them as small BIGNUMs didn't make much difference, but it 
simplified the language.


More information about the Python-list mailing list