I was recently comparing the amount of memory occupied by a Python set
to that occupied by a frozenset
using Pympler:
>>> from pympler.asizeof import asizeof
>>> x = range(100)
>>> s = set(x)
>>> f0 = frozenset(x)
>>> f1 = frozenset(s)
>>> asizeof(s)
10824
>>> asizeof(f0)
10824
>>> asizeof(f1)
6728
>>> f0==f1
True
Why would a frozenset
created from a set
occupy a different amount of memory than one created from some other iterable? Or is this just a quirk of how Pympler approximates the amount of memory occupied by a variable in Python?
This is due to the frozenset constructor logic in C, but it's indeed possibly worth a CPython bug report.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With