Created
May 10, 2012 13:57
-
-
Save ashwin/2653163 to your computer and use it in GitHub Desktop.
Size of objects in Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Tried with Python 3.2.2 64-bit | |
import sys | |
a = None | |
sys.getsizeof( a ) # 16 | |
a = 0 | |
sys.getsizeof( a ) # 24 | |
a = 12345678 | |
sys.getsizeof( a ) # 28 | |
a = "" | |
sys.getsizeof( a ) # 58 | |
a = "hello" | |
sys.getsizeof( a ) # 68 (2 bytes per letter) | |
a = [] | |
sys.getsizeof( a ) # 64 | |
a = tuple() | |
sys.getsizeof( a ) # 48 | |
a = set() | |
sys.getsizeof( a ) # 224 | |
a = {} | |
sys.getsizeof( a ) # 272 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment