File: LP6E/Chapter32/slots-test.py
import timeit
base = """
Is = []
for i in range(1000):
I = C()
I.a = 1; I.b = 2; I.c = 3; I.d = 4
t = I.a + I.b + I.c + I.d
Is.append(I)
"""
stmt = """
class C:
__slots__ = ['a', 'b', 'c', 'd']
""" + base
print('Slots =>', end=' ')
print(min(timeit.repeat(stmt, number=1000, repeat=5)))
stmt = """
class C:
pass
""" + base
print('Nonslots=>', end=' ')
print(min(timeit.repeat(stmt, number=1000, repeat=5)))