Run the given function f repeatedly, return the average elapsed time.

def benchmark(f, n_repeats=3, warmup=True, name=""):
    """
    Run the given function f repeatedly, return the average elapsed time.
    """
    if warmup:
        f()

    total_time = 0
    for i in range(n_repeats):
        iter_name = "%s (iter #%d)" % (name, i + 1,)
        with Timer(iter_name) as t:
            f()
        total_time += t.elapsed
    return total_time / n_repeats