Performance of Python builtins

Discussion in 'Python' started by miller.paul.w@gmail.com, May 26, 2008.

  1. Guest

    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
    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/python/trunk/Objects/listsort.txt
    where Python's sorting algorithm is described, except with the focus
    on other built-in constructs.

    Thanks!
    , May 26, 2008
    #1
    1. Advertising

  2. Paul Rubin Guest

    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 is O(1), but I don't really know that for sure, since it
    > would depend a lot on the internal implementation.


    list 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 ;-).
    Paul Rubin, May 26, 2008
    #2
    1. Advertising

  3. Guest

    On May 25, 7:35 pm, Paul Rubin <http://> wrote:
    > 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.
    , May 26, 2008
    #3
  4. Terry Reedy Guest

    <> wrote in message
    news:...
    | 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.
    Terry Reedy, May 26, 2008
    #4
  5. Guest

    On May 25, 9:43 pm, "Terry Reedy" <> wrote:
    > <> wrote in message
    >
    > news:...
    > | 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?
    , May 26, 2008
    #5
  6. Benjamin Guest

    On May 25, 6:19 pm, 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
    > 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!
    Benjamin, May 26, 2008
    #6
  7. Guest

    , May 26, 2008
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Sean 'Shaleh' Perry

    Re: Least used builtins?

    Sean 'Shaleh' Perry, Jul 4, 2003, in forum: Python
    Replies:
    2
    Views:
    330
    Lulu of the Lotus-Eaters
    Jul 5, 2003
  2. Raymond Hettinger
    Replies:
    8
    Views:
    309
    Daniel 'Dang' Griffith
    Apr 21, 2004
  3. Raymond Hettinger
    Replies:
    0
    Views:
    311
    Raymond Hettinger
    Apr 19, 2004
  4. Michael Hoffman
    Replies:
    3
    Views:
    461
    Bruno Desthuilliers
    Mar 19, 2005
  5. Steve Holden

    Re: execute bash builtins in python

    Steve Holden, Mar 12, 2010, in forum: Python
    Replies:
    1
    Views:
    329
    Nobody
    Mar 17, 2010
Loading...

Share This Page