source: branches/decorate/test_cached.py @ 855

Revision 855, 868 bytes checked in by mmckerns, 5 months ago (diff)

updated copyright to 2016

Line 
1#!/usr/bin/env python
2#
3# Author: Mike McKerns (mmckerns @caltech and @uqfoundation)
4# Copyright (c) 2012-2016 California Institute of Technology.
5# License: 3-clause BSD.  The full license text is available at:
6#  - http://mmckerns.github.io/project/mystic/browser/mystic/LICENSE
7
8#from mystic.cache import inf_cache as memoized
9#from klepto.safe import inf_cache as memoized
10from memoize import memoize as memoized
11
12from klepto.archives import file_archive
13from timer import timed
14
15# here caching saves time in a recursive function...
16@memoized()
17@timed()
18def fibonacci(n):
19    "Return the nth fibonacci number."
20    if n in (0, 1):
21        return n
22    print 'calculating %s' % n
23    return fibonacci(n-1) + fibonacci(n-2)
24
25fibonacci.archive(file_archive('fibonacci.pkl'))
26fibonacci.load()
27
28print fibonacci(7)
29print fibonacci(9)
30
31fibonacci.dump()
32
33
34# EOF
Note: See TracBrowser for help on using the repository browser.