3 ms·
I thought I'd add to this (because I was surprised) that the equivalent namedtuple is also 56 bytes (I expected it to be larger) and the equivalent dataclass is
by joshuamorton 5y ago
I thought I'd add to this (because I was surprised) that the equivalent namedtuple is also 56 bytes (I expected it to be larger) and the equivalent dataclass is a mere 48 bytes. (although there's overhead for defining a namedtuple or a dataclass, on the order of a constant 1kb).
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.
- masklinn 5y ago> and the equivalent dataclass is a mere 48 bytes > 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”.