import gc
import time


def measure(func, inner_iterations=1, repeats=5):
    """
    Runs func ``repeats`` times and returns the fastest speed
    (inner loop iterations per second). Use ``inner_iterations`` to specify
    the number of inner loop iterations.

    Use this function for long-running functions.
    """
    gc.disable()
    times = []
    for x in range(repeats):
        start = time.time()
        func()
        times.append(time.time() - start)

    gc.enable()
    return inner_iterations/min(times)