You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

49 lines
1.0KB

  1. import sys
  2. import time
  3. from collections import namedtuple
  4. from memory_profiler import profile
  5. class A:
  6. __slots__ = ('_name', '_age', '_score')
  7. def __init__(self, name=None, age=None, score=None):
  8. self._name = 'aaaa'
  9. self._age = 'vbba'
  10. self._score = '1111'
  11. def test1(self):
  12. num =1
  13. while True:
  14. num = num + 1
  15. if num > 1000000:
  16. break
  17. ddd=self._name
  18. for i in range(100):
  19. ddd
  20. class B(A):
  21. # __slots__ = ()
  22. def __init__(self):
  23. super().__init__()
  24. def test(self):
  25. print(self._name)
  26. a= A()
  27. b = B()
  28. b.test()
  29. # print(b._name)
  30. # print(sys.getsizeof(a), sys.getsizeof(b))
  31. # print(sys.getsizeof(a.__dict__), sys.getsizeof(b.__dict__))
  32. @profile
  33. def main():
  34. Point = namedtuple('Point', ('x', 'y', 'z'))
  35. object_list = [Point(i,i,i) for i in range(100000)]
  36. if __name__=='__main__':
  37. # main()
  38. # print(A().__dict__)
  39. ss = time.time()
  40. A().test1()
  41. print(time.time() - ss)