|
|
|
|
|
by dagw
3643 days ago
|
|
It used to be common practice to cache useful routines (e.g. start with "os_path_join = os.path.join" before the loop and call "os_path_join" instead of "os.path.join"), thus avoiding the iterative lookup on each iteration. I'll admit to being skeptical to how big an effect this would have, but it was bigger than I thought: %%timeit
s=0
for i in itertools.repeat(1.0, 1000000):
s+=math.sin(i)
10 loops, best of 3: 124 ms per loop
vs %%timeit
s=0
math_sin=math.sin
for i in itertools.repeat(1.0, 1000000):
s+=math_sin(i)
10 loops, best of 3: 89.1 ms per loop
|
|