timeit(d(
    """
    count = -1
    for _ in s:
        count += 1
    count += 1
    """
    ), 's = range(1000)')
timeit(d(
    """
    count = -1
    for count, _ in enumerate(s):
        pass
    count += 1
    """
    ), 's = range(1000)')
Length of a finite generator