Performance of int/long in Python 3
Steven D'Aprano
steve+comp.lang.python at pearwood.info
Mon Mar 25 20:17:04 EDT 2013
On Mon, 25 Mar 2013 16:16:05 -0700, Ethan Furman wrote:
> On 03/25/2013 02:51 PM, Chris Angelico wrote:
>> Python 3's int is faster than Python 2's long, but slower than Python
>> 2's int. So the question really is, would a two-form representation be
>> beneficial, and if so, is it worth the coding trouble?
>
> I'm inclined to say it's not worth the trouble. If you're working with
> numbers, and speed is an issue, you really should be using one of the
> numeric or scientific packages out there.
Or PyPy, which will probably optimize it just fine.
Also, speaking as somebody who remembers a time when ints where not
automatically promoted to longs (introduced in, Python 2.2, I think?) let
me say that having a single unified int type is *fantastic*, and managing
ints/longs by hand is a right royal PITA.
What I would like to see though is a module where I can import fixed-
width signed and unsigned integers that behave like in C, complete with
overflow, for writing code that matches the same behaviour as other
languages.
--
Steven
More information about the Python-list
mailing list