I would like to be able to calculate the number of bytes occupied by my dictionary when running my code with the PyPy interpreter. I do not know ahead of time what the keys of the dictionary will be, nor do I know what the values of those keys will be. This is what I know:
- All keys will be type
string
- The number of keys is unknown
- All values will be type
string
,int
,double
, orNone
I understand that there are no direct alternatives to sys.getsizeof()
based on the explanation provided in the failure message. The answers provided here, for the most part, link to iterative solutions that implement sys.getsizeof()
in some way or another.
Entries for the dictionary are loaded from a JSON file, so they look like some variation of this format:
{'a': 'hello', 'b': None, 'c': 20, 'd': 20.5}
Is there a way that I can calculate the amount of bytes being represented by this object without using sys.getsizeof()
? I am having a hard time googling a solution and am hoping for some insight here.