Skip to content

Instantly share code, notes, and snippets.

@flopezluis
Last active December 31, 2015 15:49
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 flopezluis/8009707 to your computer and use it in GitHub Desktop.
Save flopezluis/8009707 to your computer and use it in GitHub Desktop.
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