really simple profiling for mere mortals
hume - simple & quick profiling for mere mortals
hume is a fun-expirement turned Python package. In short, it exposes a decorator
profile that you can use to measure
the execution time of functions. It goes out of its way to make its protocol clear, usage simple, and configuration flexible.
hume adds overhead, which means its measurements are slower than real execution time. Don't use it for benchmarking.
Note: Python >= 3.6 required.
You can install
hume from PyPI:
pip install hume
pipenv install hume
A simple decorator to measure function execution times.
- Supports N simulations and average times.
- Supports, recognizes, and reports recursive functions.
- (optional) List
kwargsas provided to the decorated function.
- (optional) Display the decorated function's return value
- (optional) Supress
False, output is only reported for one simulation)
profile does not in any way modify what's returned by the decorated function. The only thing it will possibly augment are
Simply decorate any function:
from hume.decorators import profile @profile(6) def slow_add(num): """ slow_add sleeps one second and returns num + 1 """ time.sleep(1) return num + 1 print(slow_add(3))
And let it do its job:
profiling slow_add ------------------------------------------------ → name: slow_add → simulations: 6 → average execution time: 1.0034156345 seconds 4
★★★ options and defaults
profile supports the following params:
nums: int = 1→ how many simulations to conduct
show_args: bool = False→ display
argspassed to the decorated function
show_kwargs: bool = False→ display
kwargspassed to the decorated function
show_result: bool = False→ display decorated function return value
mute_console: bool = False→ supress
1 Even if
False, recursive functions will print normally and not per
For recursive functions,
profile just knows (and doesn't pollute the console):
# recursive function @profile(2) def factorial(n): if n == 1: return 1 return n * factorial(n - 1) factorial(3)
profiling factorial (recursive function detected) ------------------------------------------------ → name: factorial → simulations: 2 → average execution time: 0.00011469949999964868 seconds
★★★ changing & overriding defaults
If you don't like
profile's default configuration, you can import the
CONFIG dict and override them. For example, if you want
profile to include the
return from the decorated function by default, you would do the following:
from hume.decorators import profile, CONFIG CONFIG["show_results"] = True @profile(2) def return_one(): return 1 # you can always override your own defaults: @profile(show_result=False) def return_two_ignored(): return 2
★★★ colorized output
Output is colorized, because priorities:
Release history Release notifications | RSS feed
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.