By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,835 Members | 1,951 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,835 IT Pros & Developers. It's quick & easy.

Performance of Python builtins

P: n/a
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
Share this Question
Share on Google+
6 Replies


P: n/a
mi***********@gmail.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

P: n/a
On May 25, 7:35*pm, Paul Rubin <http://phr...@NOSPAM.invalidwrote:
miller.pau...@gmail.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

P: n/a

<mi***********@gmail.comwrote in message
news:d7**********************************@k37g2000 hsf.googlegroups.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

P: n/a
On May 25, 9:43*pm, "Terry Reedy" <tjre...@udel.eduwrote:
<miller.pau...@gmail.comwrote in message

news:d7**********************************@k37g2000 hsf.googlegroups.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

P: n/a
On May 25, 6:19 pm, miller.pau...@gmail.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

P: n/a
On May 25, 11:05*pm, Benjamin <musiccomposit...@gmail.comwrote:
http://wiki.python.org/moin/TimeComplexityis a start.
Awesome. That's pretty much what I was after!
Jun 27 '08 #7

This discussion thread is closed

Replies have been disabled for this discussion.