473,603 Members | 2,649 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Performance of Python builtins

Is there any place outside the actual C source for Python that has
information about the performance of Python's built-in operations? For
example, I'd *expect* list.append to be O(1), and I hope that list[i]
is O(1), but I don't really know that for sure, since it would depend
a lot on the internal implementation.

I'm really only asking this for curiosity's sake --- more as a
reasonable, non-trollish version of the "Python is slow" post than
anything. :-) I've never really had any problems with the performance
of Python code that I couldn't solve by either changing my algorithm
or, if all else has truly failed, rewriting in C or Pyrex.

What I'd like to see is something like http://svn.python.org/projects/pytho...s/listsort.txt
where Python's sorting algorithm is described, except with the focus
on other built-in constructs.

Thanks!
Jun 27 '08 #1
6 1377
mi***********@g mail.com writes:
Is there any place outside the actual C source for Python that has
information about the performance of Python's built-in operations?
Really, just the source code and the general culture. It's not in the
docs; that would be a pretty rare thing.
For example, I'd *expect* list.append to be O(1), and I hope that
list[i] is O(1), but I don't really know that for sure, since it
would depend a lot on the internal implementation.
list[i] is O(1). list.append is amortized O(1) but on some calls can
take much longer. Basically list.append preallocates some extra space
for further appends but when you use up the extra space there is some
copying.
I'm really only asking this for curiosity's sake --- more as a
reasonable, non-trollish version of the "Python is slow" post than
anything. :-) I've never really had any problems with the performance
of Python code that I couldn't solve by either changing my algorithm
or, if all else has truly failed, rewriting in C or Pyrex.
"You can fix your Python program's performance problems by rewriting
it in C" is not that convincing an answer to a concern that Python is
slow ;-).
Jun 27 '08 #2
On May 25, 7:35*pm, Paul Rubin <http://phr...@NOSPAM.i nvalidwrote:
miller.pau...@g mail.com writes:
Thanks for your reply. I guess I'll have to go source diving to truly
answer the question.
"You can fix your Python program's performance problems by rewriting
it in C" is not that convincing an answer to a concern that Python is
slow ;-).
Wasn't meant to be. But, it is a credit to Guido that, beyond the
pain inherent in coding in C, there's relatively little pain involved
in writing an extension module.
Jun 27 '08 #3

<mi***********@ gmail.comwrote in message
news:d7******** *************** ***********@k37 g2000hsf.google groups.com...
| Is there any place outside the actual C source for Python that has
| information about the performance of Python's built-in operations?

Unfortunately no. Guido does not want to put guarantees in the language
definition, so there is no urgency to document this. An auxiliary doc
might be accepted. But the people who could write such a thing are busy
doing otherwise. Certainly, no one has volunteered to write *and update*
such.

Jun 27 '08 #4
On May 25, 9:43*pm, "Terry Reedy" <tjre...@udel.e duwrote:
<miller.pau...@ gmail.comwrote in message

news:d7******** *************** ***********@k37 g2000hsf.google groups.com...
| Is there any place outside the actual C source for Python that has
| information about the performance of Python's built-in operations?

Unfortunately no. *Guido does not want to put guarantees in the language
definition, so there is no urgency to document this. *An auxiliary doc
might be accepted. *But the people who could write such a thing are busy
doing otherwise. *Certainly, no one has volunteered to write *and update*
such.
I see. Just to be clear, though, I wasn't looking for "guarantees " as
such, like (I believe) the STL sometimes provides. I was just looking
for some idea of what current implementations ' performance
characteristics are.

I suppose I could probably create such a resource. Keeping it updated
would be another thing entirely, since I don't really want to monitor
every single commit to Python's svn repository. Hypothetically, if
someone made such a document, do you think it could be arranged for
that person to be notified whenever CPython's implementation changes
to invalidate it?
Jun 27 '08 #5
On May 25, 6:19 pm, miller.pau...@g mail.com wrote:
Is there any place outside the actual C source for Python that has
information about the performance of Python's built-in operations? For
example, I'd *expect* list.append to be O(1), and I hope that list[i]
is O(1), but I don't really know that for sure, since it would depend
a lot on the internal implementation.

I'm really only asking this for curiosity's sake --- more as a
reasonable, non-trollish version of the "Python is slow" post than
anything. :-) I've never really had any problems with the performance
of Python code that I couldn't solve by either changing my algorithm
or, if all else has truly failed, rewriting in C or Pyrex.

What I'd like to see is something likehttp://svn.python.org/projects/python/trunk/Objects/listsort.txt
where Python's sorting algorithm is described, except with the focus
on other built-in constructs.
http://wiki.python.org/moin/TimeComplexity is a start.
>
Thanks!
Jun 27 '08 #6
On May 25, 11:05*pm, Benjamin <musiccomposit. ..@gmail.comwro te:
http://wiki.python.org/moin/TimeComplexityis a start.
Awesome. That's pretty much what I was after!
Jun 27 '08 #7

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

Similar topics

699
33745
by: mike420 | last post by:
I think everyone who used Python will agree that its syntax is the best thing going for it. It is very readable and easy for everyone to learn. But, Python does not a have very good macro capabilities, unfortunately. I'd like to know if it may be possible to add a powerful macro system to Python, while keeping its amazing syntax, and if it could be possible to add Pythonistic syntax to Lisp or Scheme, while keeping all of the...
226
12456
by: Stephen C. Waterbury | last post by:
This seems like it ought to work, according to the description of reduce(), but it doesn't. Is this a bug, or am I missing something? Python 2.3.2 (#1, Oct 20 2003, 01:04:35) on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> d1 = {'a':1} >>> d2 = {'b':2} >>> d3 = {'c':3}
46
4206
by: Scott Chapman | last post by:
There seems to be an inconsistency here: Python 2.3.2 (#1, Oct 3 2003, 19:04:58) on linux2 >>> 1 == True True >>> 3 == True False >>> if 1: print "true" ....
39
3143
by: Marco Aschwanden | last post by:
Hi I don't have to talk about the beauty of Python and its clear and readable syntax... but there are a few things that striked me while learning Python. I have collected those thoughts. I am sure there are many discussions on the "problems" mentioned here. But I had this thoughts without looking into any forums or anything... it is kind of feedback.
176
8073
by: Thomas Reichelt | last post by:
Moin, short question: is there any language combining the syntax, flexibility and great programming experience of Python with static typing? Is there a project to add static typing to Python? Thank you, -- greetz tom
3
1753
by: Michael Hoffman | last post by:
I was compelled to write this today for some reason. builtins = """__import__ abs basestring bool callable chr classmethod cmp compile complex delattr dict dir divmod enumerate eval execfile file filter float frozenset getattr globals hasattr hash help hex id input int isinstance issubclass iter len list locals long map max min object oct open ord pow property range raw_input reduce
105
5280
by: Christoph Zwerschke | last post by:
Sometimes I find myself stumbling over Python issues which have to do with what I perceive as a lack of orthogonality. For instance, I just wanted to use the index() method on a tuple which does not work. It only works on lists and strings, for no obvious reason. Why not on all sequence types? Or, another example, the index() method has start and end parameters for lists and strings. The count() method also has start and end parameters...
0
7996
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
7928
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8415
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8273
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6735
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
5878
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
3951
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2430
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
1259
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.