Advertisement
Guest User

Untitled

a guest
Nov 10th, 2019
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.96 KB | None | 0 0
  1. #Result are just the same for all, they are all in the same bucket of micro seconds
  2.  
  3.     tries = 1000000
  4.     tests = [
  5.         'def count_capitals(word):return sum([1 for _ in word if _.isupper()]);count_capitals("AbJiiHhI")',
  6.         'def count_capitals(word):return len([1 for _ in word if _.isupper()]);count_capitals("AbJiiHhI")',
  7.         'def count_capitals(word):return len([_ for _ in word if _.isupper()]);count_capitals("AbJiiHhI")',
  8.         'def count_capitals(word):return len([c for c in word if c.isupper()]);count_capitals("AbJiiHhI")',
  9.         'def count_capitals(word):return sum(_.isupper() for _ in word);count_capitals("AbJiiHhI")',
  10.         'def count_capitals(word):return sum(map(str.isupper, s));count_capitals("AbJiiHhI")',
  11.     ]
  12.  
  13.     for test in tests:
  14.         r = timeit.timeit(test, number=tries)
  15.         print(r)
  16.  
  17. # 0.11390619999999996
  18. # 0.11634690000000003
  19. # 0.12341920000000006
  20. # 0.1153246
  21. # 0.11556100000000002
  22. # 0.11212420000000001
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement