Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Result are just the same for all, they are all in the same bucket of micro seconds
- tries = 1000000
- tests = [
- 'def count_capitals(word):return sum([1 for _ in word if _.isupper()]);count_capitals("AbJiiHhI")',
- 'def count_capitals(word):return len([1 for _ in word if _.isupper()]);count_capitals("AbJiiHhI")',
- 'def count_capitals(word):return len([_ for _ in word if _.isupper()]);count_capitals("AbJiiHhI")',
- 'def count_capitals(word):return len([c for c in word if c.isupper()]);count_capitals("AbJiiHhI")',
- 'def count_capitals(word):return sum(_.isupper() for _ in word);count_capitals("AbJiiHhI")',
- 'def count_capitals(word):return sum(map(str.isupper, s));count_capitals("AbJiiHhI")',
- ]
- for test in tests:
- r = timeit.timeit(test, number=tries)
- print(r)
- # 0.11390619999999996
- # 0.11634690000000003
- # 0.12341920000000006
- # 0.1153246
- # 0.11556100000000002
- # 0.11212420000000001
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement