eallik

Untitled

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