Performance of int/long in Python 3

Ian Kelly ian.g.kelly at gmail.com
Wed Apr 3 12:53:43 EDT 2013


On Wed, Apr 3, 2013 at 1:53 AM, Steven D'Aprano
<steve+comp.lang.python at pearwood.info> wrote:
> (sys.getsizeof(s) - sys.getsizeof(''))/len(s)

>>> s = '\x80\x81\x82\x83\x84\x85'
>>> len(s)
6
>>> import sys
>>> sys.getsizeof(s)
43
>>> sys.getsizeof(s) - sys.getsizeof('')
18
>>> (sys.getsizeof(s) - sys.getsizeof('')) / len(s)
3.0

I didn't know there was a 3-byte-width representation. :-)

More seriously, it fails because '' is ASCII and s is not, and the
overhead for the two strings is different.



More information about the Python-list mailing list