def timed(name=None, file=sys.stdout, callback=None, wall_clock=True):
    """
    Context manager to make it easy to time the execution of a piece of code.
    This timer will never run your code several times and is meant more for
    simple in-production timing, instead of benchmarking. Reports the
    wall-clock time (using `time.time`) and not the processor time.

    Parameters
    ----------
    name : str
        Name of the timing block, to identify it.
    file : file handler
        Which file handler to print the results to. Default is standard output.
        If a numpy array and size 1 is given, the time in seconds will be
        stored inside it. Ignored if `callback` is set.
    callback : callable
        This offer even more flexibility than `file`. The callable will be
        called at the end of the execution with a single floating point
        argument with the elapsed time in seconds.

    Examples
    --------
    >>> import deepdish as dd
    >>> import time

    The `timed` function is a context manager, so everything inside the
    ``with`` block will be timed. The results will be printed by default to
    standard output:

    >>> with dd.timed('Sleep'):  # doctest: +SKIP
    ...     time.sleep(1)
    [timed] Sleep: 1.001035451889038 s

    Using the `callback` parameter, we can accumulate multiple runs into a
    list:

    >>> times = []
    >>> for i in range(3):  # doctest: +SKIP
    ...     with dd.timed(callback=times.append):
    ...         time.sleep(1)
    >>> times  # doctest: +SKIP
    [1.0035350322723389, 1.0035550594329834, 1.0039470195770264]
    """
    start = time.time()
    yield
    end = time.time()
    delta = end - start
    if callback is not None:
        callback(delta)
    elif isinstance(file, np.ndarray) and len(file) == 1:
        file[0] = delta
    else:
        name_str = ' {}'.format(name) if name is not None else ''
        print(("[timed]{0}: {1} s".format(name_str, delta)), file=file)
def timed ( name = None , file = sys . stdout , callback = None , wall_clock = True ) : start = time . time ( ) yield end = time . time ( ) delta = end - start if callback is not None : callback ( delta ) elif isinstance ( file , np . ndarray ) and len ( file ) == 1 : file [ 0 ] = delta else : name_str = ' {}' . format ( name ) if name is not None else '' print ( ( "[timed]{0}: {1} s" . format ( name_str , delta ) ) , file = file )
Context manager to make it easy to time the execution of a piece of code.
    This timer will never run your code several times and is meant more for
    simple in-production timing, instead of benchmarking. Reports the
    wall-clock time (using `time.time`) and not the processor time.

    Parameters
    ----------
    name : str
        Name of the timing block, to identify it.
    file : file handler
        Which file handler to print the results to. Default is standard output.
        If a numpy array and size 1 is given, the time in seconds will be
        stored inside it. Ignored if `callback` is set.
    callback : callable
        This offer even more flexibility than `file`. The callable will be
        called at the end of the execution with a single floating point
        argument with the elapsed time in seconds.

    Examples
    --------
    >>> import deepdish as dd
    >>> import time

    The `timed` function is a context manager, so everything inside the
    ``with`` block will be timed. The results will be printed by default to
    standard output:

    >>> with dd.timed('Sleep'):  # doctest: +SKIP
    ...     time.sleep(1)
    [timed] Sleep: 1.001035451889038 s

    Using the `callback` parameter, we can accumulate multiple runs into a
    list:

    >>> times = []
    >>> for i in range(3):  # doctest: +SKIP
    ...     with dd.timed(callback=times.append):
    ...         time.sleep(1)
    >>> times  # doctest: +SKIP
    [1.0035350322723389, 1.0035550594329834, 1.0039470195770264]