Skip to content

Instantly share code, notes, and snippets.

@mahmoud
Created February 18, 2015 20:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mahmoud/c9bedf486562ed4dff98 to your computer and use it in GitHub Desktop.
Save mahmoud/c9bedf486562ed4dff98 to your computer and use it in GitHub Desktop.
Timeits!
# "in" faster than re search for single character searches
# PS also held true for longer strings
$ python -m timeit -s 'import re; _re = re.compile("[{]",re.UNICODE); target = "wwoooo{ooo"' '_re.search(target)'
10000000 loops, best of 3: 0.159 usec per loop
$ python -m timeit -s 'target = "wwoooo{ooo"' '"{" in target'
10000000 loops, best of 3: 0.0269 usec per loop
#####
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment