performance - why simple for loop with if condition is faster than conditional generator expression in python -
why loop if condition in first case more 2 times faster second case conditional generator expression?
%%timeit in range(100000): if < 10000: continue pass
clocks @ 100 loops, best of 3: 2.85 ms per loop, while using generator expression:
%%timeit in (i in range(100000) if >= 10000): pass
100 loops, best of 3: 6.03 ms per loop
first version: each element in range: assign i
.
second version: each element in range: assign inner i
(third 1 left), evaluate expression i
(the i
...(i for...
assign result "outer" (leftmost) i
.
the if
statements have similar performance impact in both versions.
Comments
Post a Comment