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)')
timeit(d(
    """
    count, _ = reduce(f, enumerate(range(1000)), (-1, -1))
    count += 1
    """
    ), d(
    """
    from functools import reduce
    def f(_, count):
        return count
    s = range(1000)
    """
    ))
timeit('count = sum(1 for _ in s)', 's = range(1000)')
timeit('count = len(tuple(s))', 's = range(1000)')
timeit('count = len(list(s))', 's = range(1000)')
timeit('count = len(list(1 for _ in s))', 's = range(1000)')
Length of a finite generator