Guest User

Untitled

a guest
Oct 18th, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.47 KB | None | 0 0
  1. class Foo():
  2.  
  3. def c1(self):
  4. return self.__class__()
  5.  
  6. def c2(self):
  7. return Foo()
  8.  
  9. f = Foo()
  10.  
  11. def f1():
  12. return f.c1()
  13.  
  14. def f2():
  15. return f.c2()
  16.  
  17. if __name__ == '__main__':
  18. import timeit
  19. n = 1000 * 1000 * 1
  20. r1 = timeit.timeit("f1()", setup="from __main__ import f1", number=n)
  21. r2 = timeit.timeit("f2()", setup="from __main__ import f2", number=n)
  22. print(r1)
  23. print(r2)
  24. pct = ((r1 - r2) / r2) * 100
  25. print('{}% Diff'.format(pct))
Add Comment
Please, Sign In to add comment