On 03.01.16 04:42, Nick Coghlan wrote:
Finally, we get to the question of relative size: are function instances larger or smaller than your typical class instance? Again, we don't have to guess, we can use the interpreter to experiment and check our assumptions:
>>> import sys >>> def f(): pass ... >>> sys.getsizeof(f) 136 >>> class C(): pass ... >>> sys.getsizeof(C()) 56
sys.getsizeof() returns only the bare size of the object, not including the size of subobjects. To calculate total size you have to sum sizes of all subobjects recursively.