Skip to content

Instantly share code, notes, and snippets.

@njamaleddine
Last active November 16, 2015 19:27
Show Gist options
  • Select an option

  • Save njamaleddine/0a90732d93c548f61665 to your computer and use it in GitHub Desktop.

Select an option

Save njamaleddine/0a90732d93c548f61665 to your computer and use it in GitHub Desktop.
In is optimized from using timeit to test
from __future__ import print_function
from timeit import timeit
layout_type = 'text_only'
def in_test():
text_required_layout_choice = (
'image_and_text', 'text_over_image', 'text_only'
)
if layout_type in text_required_layout_choice:
return True
def or_test():
if (
layout_type == 'image_and_text' or
layout_type == 'text_over_image' or
layout_type == 'text_only'
):
return True
print("Testing `in`: {}".format(timeit('in_test()', 'from __main__ import in_test')))
print("Testing `or`: {}".format(timeit('or_test()', 'from __main__ import or_test')))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment