Created
May 25, 2016 23:20
-
-
Save Torxed/d4297df9e0e64f4d5c3776a974355e5b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from time import time | |
theList = [1, 2, True, False, False] | |
for y in range(3): | |
start = time() | |
for i in range(1000000): | |
result = [x for x in theList if type(x) is bool] | |
end = time() | |
first = end-start | |
start = time() | |
for i in range(1000000): | |
result = [x for x in theList if isinstance(x, bool)] | |
end = time() | |
second = end-start | |
start = time() | |
for i in range(1000000): | |
result = any(isinstance(x, bool) for x in theList) | |
end = time() | |
third = end-start | |
print('type() check:', first) | |
print('isinstance() check:', second) | |
print('any() check:', third) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment