import time


def time_function(f, name=None, on=True):
    """
    Simple decorator used for timing functions.
    More capable timing suites exist, but this suffices for many purposes.

    Can be disabled by setting `on` to False.

    Usage:
        >>> @time_function
        >>> def func(x):
        >>>     pass
    """
    if not on:
        return f
    if name is None:
        name = f.__qualname__

    def f_timed(*args, **kwargs):
        start = time.time()
        f(*args, **kwargs)
        time_diff = time.time() - start
        print('{}: {} sec'.format(name, time_diff))
        return time_diff
    return f_timed