Last active
December 19, 2018 10:47
-
-
Save worldmind/3b0f9e068757da7e75f0f7a09585ec5a to your computer and use it in GitHub Desktop.
Compare object sizes in python 3.6
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import attr | |
from pympler import asizeof | |
@attr.s() | |
class Coordinates(): | |
x = attr.ib() | |
y = attr.ib() | |
c = Coordinates(x=1, y=2) | |
@attr.s(slots=True) | |
class CoordinatesSlots(): | |
x = attr.ib() | |
y = attr.ib() | |
a = Coordinates(x=1, y=2) | |
b = CoordinatesSlots(x=1, y=2) | |
print('No slot: ', asizeof.asizeof(a)) | |
print('With slot: ', asizeof.asizeof(b)) |
Author
worldmind
commented
Dec 19, 2018
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment