Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- import time
- slots = 'a b c d e f g h i j'.split()
- class unslotty(object):
- def __init__(self):
- for attr in slots:
- setattr(self, attr, 1)
- def doit(self):
- self.b += self.a
- self.c = self.a + self.b
- self.d = self.c + self.b
- self.e = self.d + self.c
- self.f = self.e + self.d
- self.g = self.f + self.e
- self.h = self.f + self.e
- self.i = self.f + self.e
- self.j = self.f + self.e
- class slotty(unslotty):
- __slots__ = slots
- def test(obj):
- start = time.time()
- for ii in xrange(100000):
- obj.doit()
- return time.time() - start
- def test_both():
- print test(unslotty())
- print test(slotty())
- if __name__ == '__main__': test_both()
Add Comment
Please, Sign In to add comment