Skip to main content

Cache functions to speed up recursion

Project description

recache

Cache functions to speed up recursion

install

From Pypi:

python -m pip install recache

From GitHub:

python -m pip install git+https://github.com/donno2048/recache

Usage

from recache import cache
def fib(n): # slow recursion
    if n < 0: return None
    if n <= 1: return 1
    return fib(n - 1) + fib(n - 2)
@cache
def cfib(n): # fast recursion
    if n < 0: return None
    if n <= 1: return 1
    return cfib(n - 1) + cfib(n - 2)

To see the exact timing see The notebook

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

recache-1.0.0.tar.gz (1.4 kB view hashes)

Uploaded Source

Built Distribution

recache-1.0.0-py3-none-any.whl (2.4 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page