Last active
December 20, 2018 11:46
-
-
Save worldmind/a5b58b0d23069320c91ed37fcaa79d4f to your computer and use it in GitHub Desktop.
Compare object sizes in python 3.6
This file contains 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
from pympler import asizeof | |
class Coordinates(): | |
def __init__(self, x, y): | |
self.x = x | |
self.y = y | |
class CoordinatesSlots(): | |
__slots__ = ('x', 'y') | |
def __init__(self, x, y): | |
self.x = x | |
self.y = y | |
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