slots
메모리 비교
print("==============withSlot=========== 메모리")
@profile
def func1():
obList1 = [WithSlots("test", 10) for i in range(100000)]
func1()
print("==============NoSlot=========== 메모리")
@profile
def func2():
obList2 = [NoSlots("test", 10) for i in range(100000)]
func2()
==============withSlot=========== 메모리
Line # Mem usage Increment Occurrences Line Contents
=============================================================
37 21.6 MiB 21.6 MiB 1 @profile
38 def func1():
39 27.9 MiB -2702.5 MiB 100003 obList1 = [WithSlots("test", 10) for i in range(100000)]
==============NoSlot=========== 메모리
Line # Mem usage Increment Occurrences Line Contents
=============================================================
46 23.1 MiB 23.1 MiB 1 @profile
47 def func2():
48 38.5 MiB 15.4 MiB 100003 obList2 = [NoSlots("test", 10)
for i in range(100000)]
실행시간 비교
print("==============withSlot=========== 실행시간")
def func3():
for i in range(100000):
obList3 = WithSlots("test", 10)
del obList3
start = time.time()
func3()
end = time.time()
sec = end - start
result = datetime.timedelta(seconds=sec)
print(result)
print("==============noSlot=========== 실행시간")
def func4():
for i in range(100000):
obList4 = NoSlots("test", 10)
del obList4
start = time.time()
func4()
end = time.time()
sec = end - start
result = datetime.timedelta(seconds=sec)
print(result)
==============withSlot=========== 실행시간
0:00:00.023078
==============noSlot=========== 실행시간
0:00:00.036217
WithSlot: 00.023078s
NoSlot: 00.036217s
할당된 메모리가 크다면 지우는 것도 그만큼 오래걸릴 것이다.