Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Why is function call - recursive especially - in python so slow?

Reply
Thread Tools

Why is function call - recursive especially - in python so slow?

 
 
iviskic@uci.edu
Guest
Posts: n/a
 
      10-18-2004

Hi,

I'm doing an analysis of program code performance when written in python
as oppose to other programming languages, and can't seem to figure out why
is the call of functions so slow?
Is a context being created and stored on stog each time, or does it uses
references? How EXACTLY does it work? I've read the documentation, but it
is written on a cooking-book principle, so it does not say clearly how it
works, just that it does work.

Please let me know if you now how it's done, or (preferably) point me
where to look for the answer.
Thank you in advance.

Ines

 
Reply With Quote
 
 
 
 
Alex Martelli
Guest
Posts: n/a
 
      10-18-2004
<> wrote:
...
> as oppose to other programming languages, and can't seem to figure out why
> is the call of functions so slow?
> Is a context being created and stored on stog each time, or does it uses


A frame object is created for each call.

> references? How EXACTLY does it work? I've read the documentation, but it

...
> Please let me know if you now how it's done, or (preferably) point me
> where to look for the answer.


The source code is the only ultimate answer to such implementation
questions. Download Python's sources and see how frame objects are
created, populated, and stacked on call, and popped and destroyed on
return (or on exit by exception propagation) from a function. ceval.c
has the huge switch on bytecodes that shows you what happens at each
bytecode -- to see what bytecode comes from a code fragment, use the dis
module (dis.dis of a small codeobject or function is instructive). Once
you see the calls which a certain bytecode causes ceval.c to make, you
can track the details over other source files.

Or if you prefer to see the implementations done in Java or C# or
O'Caml, all of Jython, IronPython and Vyper are open-source, too, of
course. You can see an incomplete implementation in Python itself in
pypy, another one in (I'm not sure, I guess perl?) in PyParrot. Of
course, each implementation can do what it wishes, as long as it
respects Python language semantics.


Alex
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Two recursive calls inside of a recursive function n00m C++ 12 03-13-2008 03:18 PM
findcontrol("PlaceHolderPrice") why why why why why why why why why why why Mr. SweatyFinger ASP .Net 2 12-02-2006 03:46 PM
defined? for recursive function call v/s defined? for function call stack Alok Ruby 3 04-13-2006 11:53 AM
Why the following codes is "especially slow" and "unformally slow"? mike Java 3 07-11-2005 05:35 PM
Re: Why is function call - recursive especially - in python so slow? Terry Reedy Python 0 10-19-2004 01:05 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57