Last active
December 31, 2015 15:49
-
-
Save flopezluis/8009707 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 clock as now | |
def catastrophic(n): | |
pat = re.compile('([a|b]+)+c') | |
text = "%s" %('a' * n) | |
pat.search(text) | |
def test(f, *args, **kargs): | |
start = now() | |
f(*args, **kargs) | |
print "The function %s lasted: %f" %(f.__name__, now() - start) | |
for n in range(20, 30): | |
test(catastrophic, n) | |
Output: | |
Testing with 20 characters | |
The function catastrophic lasted: 0.130457 | |
Testing with 21 characters | |
The function catastrophic lasted: 0.245125 | |
…… | |
The function catastrophic lasted: 14.828221 | |
Testing with 28 characters | |
The function catastrophic lasted: 29.830929 | |
Testing with 29 characters | |
The function catastrophic lasted: 61.110949 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment