Advertisement
eallik

Untitled

Apr 12th, 2014
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.38 KB | None | 0 0
  1. In [6]: i = 4
  2.  
  3. In [7]: timeit "Fizz" * (i % 3 == 0)
  4. 10000000 loops, best of 3: 118 ns per loop
  5.  
  6. In [8]: timeit "Fizz" if i % 3 == 0 else ""
  7. 10000000 loops, best of 3: 72 ns per loop
  8.  
  9. In [9]: i = 3
  10.  
  11. In [10]: timeit "Fizz" * (i % 3 == 0)
  12. 10000000 loops, best of 3: 110 ns per loop
  13.  
  14. In [11]: timeit "Fizz" if i % 3 == 0 else ""
  15. 10000000 loops, best of 3: 72.2 ns per loop
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement