Reading Time: 1 minutes
Getting size of an object in memory in Python
The getsizeof() function of sys module tells us about the size of an object in memory in bytes. This can be particularly useful while identifying performance bottlenecks.
>>> import sys >>> sys.getsizeof(5) 14 >>> sys.getsizeof('hello') 30 >>> sys.getsizeof( [1, 2, 3, 4] ) 52