Hi,

I'm working on auto-generated python code with the exec function. I've done
some performance benches :

% python -m timeit '1 + 1'
10000000 loops, best of 3: 0.0229 usec per loop

% python -m timeit "exec('1 + 1')"
100000 loops, best of 3: 11.6 usec per loop

-> Maybe creating an exec environnement (I don't know how it works) takes
time. But :

% python -m timeit "1 + 1; 1 + 1"
10000000 loops, best of 3: 0.042 usec per loop

% python -m timeit "exec('1 + 1; 1 + 1')"
100000 loops, best of 3: 15.7 usec per loop

-> As if executing one more 1 + 1 would take 4 more seconds (100000
iterations) in an exec environnement.

Am I missing something or should I expect that result ? What does using
exec imply that causes such a difference ?

Jean-Baptiste Braun
-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to