python - getting different object size with different functions -


why code snippet giving different size in bytes 2 different functions. using 32 bit version of python 2.7.3

1) dictionaries:-

from sys import getsizeof l = range(20)             d = {k:v k,v in enumerate(l)}    #creating dict d.__sizeof__()   #gives size in bytes  508              #size of dictionary 'd' in bytes  getsizeof(d) 524              #size of same dictionary 'd' in bytes (which different above) 

2) list:-

from sys import getsizeof l = range(20) l.__sizeof__()    100           #size of list 'l' in bytes  getsizeof(l) 116           #size of same list 'l' in bytes 

3) tuple:-

from sys import getsizeof t = tuple(range(20)) t.__sizeof__() 92             #size of tuple 't' in bytes  getsizeof(t) 108            #size of same tuple 't' in bytes 

would tell me why kind of behaviour, when documentation of both function says return size of object in bytes.

from sys docs:

getsizeof() calls object’s sizeof method and adds additional garbage collector overhead if object managed garbage collector.

i'm guessing explains discrepancy.


Comments

Popular posts from this blog

matlab - Deleting rows with specific rules -

php - MySQLi multi_query results for later use -