49 lines
1.0 KiB
Python
49 lines
1.0 KiB
Python
import sys
|
|
import time
|
|
from collections import namedtuple
|
|
|
|
from memory_profiler import profile
|
|
|
|
class A:
|
|
|
|
__slots__ = ('_name', '_age', '_score')
|
|
|
|
def __init__(self, name=None, age=None, score=None):
|
|
self._name = 'aaaa'
|
|
self._age = 'vbba'
|
|
self._score = '1111'
|
|
|
|
def test1(self):
|
|
num =1
|
|
while True:
|
|
num = num + 1
|
|
if num > 1000000:
|
|
break
|
|
ddd=self._name
|
|
for i in range(100):
|
|
ddd
|
|
|
|
class B(A):
|
|
# __slots__ = ()
|
|
def __init__(self):
|
|
super().__init__()
|
|
|
|
def test(self):
|
|
print(self._name)
|
|
a= A()
|
|
b = B()
|
|
b.test()
|
|
# print(b._name)
|
|
# print(sys.getsizeof(a), sys.getsizeof(b))
|
|
# print(sys.getsizeof(a.__dict__), sys.getsizeof(b.__dict__))
|
|
@profile
|
|
def main():
|
|
Point = namedtuple('Point', ('x', 'y', 'z'))
|
|
object_list = [Point(i,i,i) for i in range(100000)]
|
|
|
|
if __name__=='__main__':
|
|
# main()
|
|
# print(A().__dict__)
|
|
ss = time.time()
|
|
A().test1()
|
|
print(time.time() - ss) |