timeit.timeit(setup='import re', stmt=
    """r=re.compile(r"\\w+")
for i in range(10):
 r.search("  jkdhf  ")""")
timeit.timeit(setup='import re', stmt=
    """for i in range(10):
 re.search(r"\\w+","  jkdhf  ")""")
Compiling Regular Expressions in Python