map lazy evaluation


In [1]:
def f(x):
    return x % 2

In [2]:
%%timeit

m = map(f, range(1000))


462 ns ± 38.4 ns per loop (mean ± std. dev. of 7 runs, 1000000 loops each)

In [3]:
%%timeit

for m in map(f, range(1000)):
    pass


98.7 µs ± 4.19 µs per loop (mean ± std. dev. of 7 runs, 10000 loops each)

calling map on a 10 times longer sequence takes roughly 10 times longer


In [4]:
%%timeit

for m in map(f, range(10000)):
    pass


941 µs ± 7.25 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)