peterpy ====
Add peter's context manager around your code and it will measure how long it takes to run:
from peterpy import peter
with peter('Running some code'):
fib = lambda n: n if n < 2 else fib(n-1) + fib(n-2)
fib(30)
Running some code... DONE (took 0.590127 seconds)
Table of contents
pip install peterpy
Pull and install in the current directory:
pip install git+https://github.com/javiribera/peterpy.git@master
class peter():
"""
Context manager that will print
the time elapsed while executing the code inside it.
"""
def __init__(self,
msg="Running",
erase_stdout=False,
erase_stderr=False):
- msg : str, optional
Message to show on standard output before running. Default: "Running..."
- erase_stdout : bool, optional
Ignore everything sent to the standard output inside the context. Default: False
- erase_stderr : bool, optional
Ignore everything sent to the standard error inside the context. Default: False