Вопрос

is there a function in Python which can find out how much memory takes a certain attribute or a variable?

EXAMPLE:

a='ThisTakesSeveralBitesOfMemory'
print(a.memoryTaken())

>> 20 b
Это было полезно?

Решение

You can use sys.getsizeof(). It returns in bytes.

>>> a='ThisTakesSeveralBitesOfMemory'
>>> sys.getsizeof(a)
50
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top