Guest User

Untitled

a guest
Jan 19th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.45 KB | None | 0 0
  1. #!/usr/bin/env python3
  2.  
  3. import timeit
  4.  
  5. def mypow1(x, y):
  6. return x ** y
  7.  
  8. def mypow2(x, y):
  9. return pow(x, y)
  10.  
  11. s1 = '2 ** 100'
  12. s2 = 'pow(2, 100)'
  13.  
  14. print(timeit.timeit(s1))
  15. print(timeit.timeit(s2))
  16.  
  17. print(timeit.timeit('mypow1(2, 100)', globals=globals()))
  18. print(timeit.timeit('mypow2(2, 100)', globals=globals()))
  19.  
  20. # repeat 3 times by default
  21. print(timeit.repeat('mypow1(2, 100)', globals=globals()))
  22. print(timeit.repeat('mypow2(2, 100)', globals=globals()))
Add Comment
Please, Sign In to add comment