(setup=None, number=10, repeat=3, warmup=5)
return real_decorator
A parametrized decorator to benchmark the test.

    Setting up the bench can happen in the normal setUp,
    which is applied to all benches identically, and additionally
    the setup parameter, which is bench-specific.

    Parameters
    ----------
    setup : function
        A function to call once to set up the test.
    number : int
        The number of loops of repeat repeats to run.
    repeat : int
        The number of repeats in each loop.
    warmup : int
        The number of warmup runs of the function.
A parametrized decorator to benchmark the test.
A parametrized decorator to benchmark the test .
def benchmark(setup=None, number=10, repeat=3, warmup=5):
    """A parametrized decorator to benchmark the test.

    Setting up the bench can happen in the normal setUp,
    which is applied to all benches identically, and additionally
    the setup parameter, which is bench-specific.

    Parameters
    ----------
    setup : function
        A function to call once to set up the test.
    number : int
        The number of loops of repeat repeats to run.
    repeat : int
        The number of repeats in each loop.
    warmup : int
        The number of warmup runs of the function.
    """
    def real_decorator(func):
        @wraps(func)
        def wrapper(self, *args, **kwargs):
            if setup is not None:
                setup(self)
            for i in range(warmup):
                func(self, *args, **kwargs)
            clock_time_starts = np.zeros((number, repeat))
            clock_time_ends = np.zeros((number, repeat))
            for i in range(number):
                for j in range(repeat):
                    clock_time_starts[i, j] = perf_counter()
                    func(self, *args, **kwargs)
                    clock_time_ends[i, j] = perf_counter()
            clock_times = (clock_time_ends - clock_time_starts).min(axis=1)

            print("[{}] with {} loops, best of {}:"
                  .format(_get_bench_name(func), number, repeat))
            print("\tmin {:4s} per loop".format(_timeitlike_time_format(clock_times.min())))
            print("\tavg {:4s} per loop".format(_timeitlike_time_format(clock_times.mean())))
        return wrapper
    return real_decorator
def benchmark ( setup = None , number = 10 , repeat = 3 , warmup = 5 ) : def real_decorator ( func ) : @ wraps ( func ) def wrapper ( self , * args , * * kwargs ) : if setup is not None : setup ( self ) for i in range ( warmup ) : func ( self , * args , * * kwargs ) clock_time_starts = np . zeros ( ( number , repeat ) ) clock_time_ends = np . zeros ( ( number , repeat ) ) for i in range ( number ) : for j in range ( repeat ) : clock_time_starts [ i , j ] = perf_counter ( ) func ( self , * args , * * kwargs ) clock_time_ends [ i , j ] = perf_counter ( ) clock_times = ( clock_time_ends - clock_time_starts ) . min ( axis = 1 ) print ( "[{}] with {} loops, best of {}:" . format ( _get_bench_name ( func ) , number , repeat ) ) print ( "\tmin {:4s} per loop" . format ( _timeitlike_time_format ( clock_times . min ( ) ) ) ) print ( "\tavg {:4s} per loop" . format ( _timeitlike_time_format ( clock_times . mean ( ) ) ) ) return wrapper return real_decorator