Skip to content

Instantly share code, notes, and snippets.

@Torxed
Created May 25, 2016 23:20
Show Gist options
  • Save Torxed/d4297df9e0e64f4d5c3776a974355e5b to your computer and use it in GitHub Desktop.
Save Torxed/d4297df9e0e64f4d5c3776a974355e5b to your computer and use it in GitHub Desktop.
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