{"x": 51.2, "y": -74.1 }
that you don't gain a lot from namedtuples most of the time. I quit benching namedtuples for applications like that a long time ago. {"x": 51.2, "y": -74.1 }
that you don't gain a lot from namedtuples most of the time. I quit benching namedtuples for applications like that a long time ago.Your dict is 232 bytes, the equivalent tuple is 56.
Although there seems to be some kind of trickery happening there, because if I make the class accept 3 floats instead of two, neither the class nor the instance get larger.
> Although there seems to be some kind of trickery happening there, because if I make the class accept 3 floats instead of two, neither the class nor the instance get larger.
The dataclass stores stuff in a normal instance __dict__ and sys.getsize is not recursive.
namedtuples are variable-size instances, they store the attributes “inline”.
I haven't tried it but type hints are probably smart enough to find errors like this statically with namedtuple, but probably not so with a dict.