def METHOD_NAME(queue, f, timer_factory=None, desired_duration=0.1,
        warmup_rounds=3):
    if timer_factory is None:
        timer_factory = WallTimer
    count = 1
    while True:
        timer = timer_factory(queue)
        for _i in range(warmup_rounds):
            f()
        warmup_rounds = 0
        timer.start()
        for _i in range(count):
            timer.add_event(f())
        timer.stop()
        elapsed = timer.get_elapsed()
        if elapsed < desired_duration:
            if elapsed == 0:
                count *= 5
            else:
                new_count = int(desired_duration/elapsed)
                new_count = max(2*count, new_count)
                new_count = min(10*count, new_count)
                count = new_count
        else:
            return elapsed/count