Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- import timeit
- def mypow1(x, y):
- return x ** y
- def mypow2(x, y):
- return pow(x, y)
- s1 = '2 ** 100'
- s2 = 'pow(2, 100)'
- print(timeit.timeit(s1))
- print(timeit.timeit(s2))
- print(timeit.timeit('mypow1(2, 100)', globals=globals()))
- print(timeit.timeit('mypow2(2, 100)', globals=globals()))
- # repeat 3 times by default
- print(timeit.repeat('mypow1(2, 100)', globals=globals()))
- print(timeit.repeat('mypow2(2, 100)', globals=globals()))
Add Comment
Please, Sign In to add comment