Advertisement
Peaser

Untitled

Sep 1st, 2015
370
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. >>> timeit.timeit(setup="d={1:2, 3:4, 5:6, 7:8, 9:0}",
  2. ... stmt="try:\n a=d[1]\nexcept KeyError:\n a=10")
  3. 0.07691968797894333
  4. >>> timeit.timeit(setup="d={1:2, 3:4, 5:6, 7:8, 9:0}",
  5. ... stmt="try:\n a=d[2]\nexcept KeyError:\n a=10")
  6. 0.4583777282275605
  7. >>> timeit.timeit(setup="d={1:2, 3:4, 5:6, 7:8, 9:0}",
  8. ... stmt="a=d.get(1, 10)")
  9. 0.17784020746671558
  10. >>> timeit.timeit(setup="d={1:2, 3:4, 5:6, 7:8, 9:0}",
  11. ... stmt="a=d.get(2, 10)")
  12. 0.17952161730158878
  13. >>> timeit.timeit(setup="d={1:2, 3:4, 5:6, 7:8, 9:0}",
  14. ... stmt="if 1 in d:\n a=d[1]\nelse:\n a=10")
  15. 0.10071221458065338
  16. >>> timeit.timeit(setup="d={1:2, 3:4, 5:6, 7:8, 9:0}",
  17. ... stmt="if 2 in d:\n a=d[2]\nelse:\n a=10")
  18. 0.06966537335119938
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement