Program uses twice as much memory in Python 3.6 than in Python 3.5

MrJean1 mrjean1 at gmail.com
Fri Mar 31 17:05:17 EDT 2017


Similarly, on  macOS 10.12.3 Sierra:

% python3.5
Python 3.5.3 (v3.5.3:1880cb95a742, Jan 16 2017, 08:49:46) 
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> s = set(range(10))
>>> sys.getsizeof(s)
736
>>> sys.getsizeof(set(s))
736
>>> sys.getsizeof(set(set(s)))
736
>>>

% python3
Python 3.6.0 (v3.6.0:41df79263a11, Dec 22 2016, 17:23:13) 
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> s = set(range(10))
>>> sys.getsizeof(s)
736
>>> sys.getsizeof(set(s))
1248
>>> sys.getsizeof(set(set(s)))
1248
>>>

% python2
Python 2.7.13 (v2.7.13:a06454b1afa1, Dec 17 2016, 12:39:47) 
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> s = set(range(10))
>>> sys.getsizeof(s)
744
>>> sys.getsizeof(set(s))
744
>>> sys.getsizeof(set(set(s)))
744
>>> 



More information about the Python-list mailing list