Why is Python so slow ?- revisited.
Bijan Parsia
bparsia at email.unc.edu
Mon Jun 19 14:15:16 EDT 2000
William Dandreta <wjdandreta at worldnet.att.net> wrote:
> Mike Fletcher wrote in message ...
> >
> >Also, don't discount the expense of an extra function call. Function calls
> >were (and still are to a lesser extent) extremely heavy in Python five
> years
> >ago.
>
> I did discount it because in assembly language a function call is little
> more than a jump. I thought that even if it were extremely inefficiently
> implimented in Python, it couldn't reduce speed by a factor of 6.
Oh you'd be surprised :)
> In
> addition, there are 3 function calls in each replace. Logic says eliminating
> one improve speed by 1/3.
Er.. no logic I know of :) Remember that "obvious" reasoning typically
leads you astray when thinking about optimization. The key, as I have
written, is the *lookup* of the method/function. These are *not*
resolved at compile time, but at run time. They are *not* cached (unless
you do so manually), they are performed from scratch each time.
> But on second thought, the one I eliminated was a call to a python.py
> library module, the other 2 function calls are to functions in strop, a
> compiled C 'module'. I'll have to test it to be sure.
Try saving the function to a local var and using it. I'd be interested
to see what happens.
--
Bijan Parsia
http://monkeyfist.com/
...among many things.
More information about the Python-list
mailing list