Guest User

Untitled

a guest
Feb 21st, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. #!/usr/bin/python
  2. import time
  3. slots = 'a b c d e f g h i j'.split()
  4. class unslotty(object):
  5. def __init__(self):
  6. for attr in slots:
  7. setattr(self, attr, 1)
  8. def doit(self):
  9. self.b += self.a
  10. self.c = self.a + self.b
  11. self.d = self.c + self.b
  12. self.e = self.d + self.c
  13. self.f = self.e + self.d
  14. self.g = self.f + self.e
  15. self.h = self.f + self.e
  16. self.i = self.f + self.e
  17. self.j = self.f + self.e
  18.  
  19. class slotty(unslotty):
  20. __slots__ = slots
  21.  
  22. def test(obj):
  23. start = time.time()
  24. for ii in xrange(100000):
  25. obj.doit()
  26. return time.time() - start
  27.  
  28. def test_both():
  29. print test(unslotty())
  30. print test(slotty())
  31.  
  32. if __name__ == '__main__': test_both()
Add Comment
Please, Sign In to add comment