Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import timeit
- def test_slots():
- class Obj(object):
- __slots__ = ('i', 'l')
- def __init__(self, i):
- self.i = i
- self.l = []
- for i in xrange(1000):
- Obj(i)
- print timeit.Timer('test_slots()', 'from __main__ import test_slots').timeit(10000)
- timeit(10) - 0.067s
- timeit(100) - 0.5s
- timeit(1000) - 19.5s
- timeit(10000) - ? (probably more than a Game of Thrones episode)
- import collections
- import timeit
- def test_namedtuples():
- Obj = collections.namedtuple('Obj', 'i l')
- for i in xrange(1000):
- Obj(i, [])
- print timeit.Timer('test_namedtuples()', 'from __main__ import test_namedtuples').timeit(10000)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement