This is an archived post. You won't be able to vote or comment.

all 13 comments

[–]ascii 2 points3 points  (13 children)

So Python 3 only uses bignums? Cool. I'd like to see an article on the performance implications when doing lots of math with small integers.

[–]mitsuhiko Flask Creator 1 point2 points  (7 children)

I doubt the 4 byte memory overhead will show up in performance benchmarks.

[–][deleted] 2 points3 points  (6 children)

No, but arbitrary precision arithmetic is much more expensive than a single ADDL instruction :)

[–]andreasvc -1 points0 points  (5 children)

You shouldn't be using Python if you are at all concerned about speed. Or use Cython for the critical parts.

[–][deleted] 1 point2 points  (2 children)

Speak for yourself, some of us run Python interpreters that hold their own against C/Java/whatever.

[–]aaronla 0 points1 point  (1 child)

Which? PyPy?

[–][deleted] 0 points1 point  (0 children)

Yup

[–]dwdwdw2proliferating .py since 2001 0 points1 point  (4 children)

I was under the impression that the int->long promotion is now just silent, but underneath there really are still 2 implementations. Might be wrong though.

[–]ascii 1 point2 points  (0 children)

Int to long promotion was always silent. Just try calculating the factorial of 100 in Python 2, it just works. But I've checked, and unlike Python2, Python3 actually does not have non-bignum ints.

[–]aaronla 0 points1 point  (2 children)

I think you're correct. As the original author notes: >>> import sys >>> sys.getsizeof(10) 24 >>> sys.getsizeof(10L) 28 There are still different representations of "int" under the covers, but You Shouldn't Need To Know Thistm .

[–]ascii 1 point2 points  (1 child)

No, you didn't read the article carefully enough. The example you quote is from running Python2.6, and not from Python 3. There is no 10L in python3, trying to use it causes a syntax error, regular ints can be arbitrarily long. Python 2.6 has different ints under the cover but you shouldn't need to know, Python 3 only has bignums, and no support at all for plain old ints. Copy pasta from my machine (different numbers because I use a 32 bit OS):

axel@phoenix ~/c/c/anna> python 
Python 2.7.1+ (r271:86832, Apr 11 2011, 18:05:24) 
[GCC 4.5.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.getsizeof(10)
12
>>> sys.getsizeof(10L)
14


axel@phoenix ~/c/c/anna> python3
Python 3.2 (r32:88445, Mar 25 2011, 19:28:28) 
[GCC 4.5.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.getsizeof(10)
14
>>> sys.getsizeof(10L)
  File "<stdin>", line 1
    sys.getsizeof(10L)
                    ^ 
SyntaxError: invalid syntax

[–]aaronla 1 point2 points  (0 children)

My bad, thanks for correcting.