473,406 Members | 2,336 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

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


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

Jul 18 '05 #1
1 2076
<iv*****@uci.edu> 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
Jul 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Derek Rhodes | last post by:
using Python 2.3.4 (#53, May 25 2004, 21:17:02) on win32 OK, I have a recursive function that should return a list, but doesn't <start session> def test(word): if type(word) == str:
4
by: Nicolas Vigier | last post by:
Hello, I have in my python script a function that look like this : def my_function(arg1, arg2, opt1=0, opt2=1, opt3=42): if type(arg1) is ListType: for a in arg1: my_function(a, arg2,...
11
by: randomtalk | last post by:
hi, i have the following recursive function (simplified to demonstrate the problem): >>> def reTest(bool): .... result = .... if not bool: .... reTest(True) .... else: .... print...
4
by: Michael | last post by:
Hi, I'm having difficulty finding any previous discussion on this -- I keep finding people either having problems calling os.exec(lepev), or with using python's exec statement. Neither of...
9
by: Mike | last post by:
While trying to write a recursive function involving lists, I came across some (to me) odd behavior which I don't quite understand. Here's a trivial function showing the problem. for itm in l:...
2
by: sebastien.abeille | last post by:
Hello, I would like to create a minimalist file browser using pyGTK. Having read lot of tutorials, it seems to me that that in my case, the best solution is to have a gtk.TreeStore containing...
18
by: Just Another Victim of the Ambient Morality | last post by:
Is pyparsing really a recursive descent parser? I ask this because there are grammars it can't parse that my recursive descent parser would parse, should I have written one. For instance: ...
3
by: from.future.import | last post by:
Hi, I encountered garbage collection behaviour that I didn't expect when using a recursive function inside another function: the definition of the inner function seems to contain a circular...
3
by: Davy | last post by:
Hi all, Sometimes I need to pass same parameter in recursive function. From my point of view, the style is redundant, and I don't what to use some global style like self.A, self.B, Is there any...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.