Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Foo():
- def c1(self):
- return self.__class__()
- def c2(self):
- return Foo()
- f = Foo()
- def f1():
- return f.c1()
- def f2():
- return f.c2()
- if __name__ == '__main__':
- import timeit
- n = 1000 * 1000 * 1
- r1 = timeit.timeit("f1()", setup="from __main__ import f1", number=n)
- r2 = timeit.timeit("f2()", setup="from __main__ import f2", number=n)
- print(r1)
- print(r2)
- pct = ((r1 - r2) / r2) * 100
- print('{}% Diff'.format(pct))
Add Comment
Please, Sign In to add comment