Performance of Python builtins

Paul Rubin http
Sun May 25 19:35:23 EDT 2008


miller.paul.w at 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 ;-).



More information about the Python-list mailing list