Skip to content

Instantly share code, notes, and snippets.

@flopezluis
Last active December 31, 2015 15:49
Show Gist options
  • Save flopezluis/8009707 to your computer and use it in GitHub Desktop.
Save flopezluis/8009707 to your computer and use it in GitHub Desktop.

Revisions

  1. flopezluis revised this gist Dec 18, 2013. No changes.
  2. flopezluis revised this gist Dec 18, 2013. No changes.
  3. flopezluis revised this gist Dec 18, 2013. 1 changed file with 25 additions and 1 deletion.
    26 changes: 25 additions & 1 deletion benchmark
    Original file line number Diff line number Diff line change
    @@ -10,8 +10,32 @@ def test(f, *args, **kargs):
    f(*args, **kargs)
    print "The function %s lasted: %f" %(f.__name__, now() - start)

    for n in range(10, 100):
    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





  4. flopezluis created this gist Dec 17, 2013.
    17 changes: 17 additions & 0 deletions benchmark
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@
    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(10, 100):
    test(catastrophic, n)