Does Python optimize function calls from loops?

后端 未结 5 522
不思量自难忘°
不思量自难忘° 2021-02-04 04:50

Say, I have a code which calls some function millions time from loop and I want the code to be fast:

def outer_function(file):
    for line in file:
        inne         


        
5条回答
  •  醉梦人生
    2021-02-04 05:25

    Calling a function to invoke the pass statement obviously carries a fairly high (∞) overhead. Whether your real program suffers undue overhead depends on the size of the inner function. If it really is just setting a pixel, then I'd suggest a different approach that uses drawing primitives coded in a native language like C or C++.

    There are (somewhat experimental) JIT compilers for Python that will optimise function calls, but mainstream Python won't do this.

提交回复
热议问题