Performance in exec environnements

Jean-Baptiste Braun jbaptiste.braun at gmail.com
Tue Jan 13 18:02:17 CET 2015


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20150113/e11d8aec/attachment.html>


More information about the Python-list mailing list