Python @ DjangoSpin

Python: Getting size of an object in memory

Buffer this pageShare on FacebookPrint this pageTweet about this on TwitterShare on Google+Share on LinkedInShare on StumbleUpon
Reading Time: 1 minutes

Getting size of an object in memory in Python

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

See also:

Buffer this pageShare on FacebookPrint this pageTweet about this on TwitterShare on Google+Share on LinkedInShare on StumbleUpon

Leave a Reply