examples/memoize/fibonacci.py
import sys
import memoize

#@memoize.memoize
def fibonacci(n):
    if n == 1:
        return 1
    if n == 2:
        return 1
    return fibonacci(n-1) + fibonacci(n-2)

if __name__ == '__main__':
    if len(sys.argv) != 2:
        sys.stderr.write("Usage: {} N\n".format(sys.argv[0]))
        exit(1)
    print(fibonacci(int(sys.argv[1])))


examples/memoize/memoize.py
def memoize(f):
    def caching(n):
        key = n
        if 'data' not in caching.__dict__:
            caching.data = {}
        if key not in caching.data:
            caching.data[key] = f(n)
        return caching.data[key]

    return caching

Before

$ time python fibonacci.py 35
9227465

real   0m3.850s
user   0m3.832s
sys    0m0.015s

After

$ time python fibonacci.py 35
9227465

real   0m0.034s
user   0m0.019s
sys    0m0.014s