Why is calling eval so slow?

Steven D'Aprano steve+comp.lang.python at pearwood.info
Sat May 5 22:29:03 EDT 2018


On Sat, 05 May 2018 20:11:28 +0300, Serhiy Storchaka wrote:

>> Why so slow?
> 
> 1. Add an overhead of calling eval(), not just looking up its name. It
> is comparable with a time of calling a simple lambda. 2. Add an overhead
> of getting the globals dict and creating a locals dict.
[...]

Ah, that makes sense.

So presumably the fastest way to run some code in Python is to put it 
into a function and call the function, rather than playing with eval or 
exec, right?



Thanks.



-- 
Steve




More information about the Python-list mailing list