Newbie Question: can this snippet be optimized?

Discussion in 'Python' started by Hedr, Jun 25, 2003.

  1. Hedr

    Hedr Guest

    Hi Pythonians,

    The underlying snippet is copied from minidom.py which is in the XML
    package which I am currently using. Cloning nodes seem to take a
    considerable amount of time, hence I went looking in the code whether
    optimizations could be made. The following snippet contains a for
    loop:

    def cloneNode(self, deep):
    clone = Node.cloneNode(self, deep)
    clone._attrs = {}
    clone._attrsNS = {}
    for attr in self._attrs.values():
    node = attr.cloneNode(1)
    clone._attrs[node.name] = node
    clone._attrsNS[(node.namespaceURI, node.localName)] = node
    node.ownerElement = clone
    return clone

    I just wondered if this could be optimized (mao, array, whatever) and
    if so, how? I do not have much experience with Python, hence the
    question.

    Thanks for suggestions,

    Hedr
     
    Hedr, Jun 25, 2003
    #1
    1. Advertisements

  2. <Hedr> wrote in message news:...
    > Hi Pythonians,
    >
    > The underlying snippet is copied from minidom.py which is in the XML
    > package which I am currently using. Cloning nodes seem to take a
    > considerable amount of time, hence I went looking in the code whether
    > optimizations could be made.



    Try applying psyco.bind() to see if you can
    get a substantial speed-up.


    Raymond Hettinger
     
    Raymond Hettinger, Jun 25, 2003
    #2
    1. Advertisements

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. Collin VanDyck
    Replies:
    3
    Views:
    592
    Collin VanDyck
    Oct 27, 2003
  2. Sonia
    Replies:
    3
    Views:
    693
    Sonia
    Sep 1, 2003
  3. Replies:
    4
    Views:
    590
    Christian Bau
    Feb 11, 2006
  4. Replies:
    12
    Views:
    781
    ma740988
    Nov 10, 2006
  5. Grizlyk

    what can be optimized?

    Grizlyk, Jan 24, 2007, in forum: C++
    Replies:
    17
    Views:
    620
    Grizlyk
    Jan 26, 2007
  6. Basilisk96

    how can this iterator be optimized?

    Basilisk96, Feb 12, 2009, in forum: Python
    Replies:
    9
    Views:
    413
    Basilisk96
    Feb 16, 2009
  7. Francois Grieu

    Can this mostly useless while loop be optimized out?

    Francois Grieu, Mar 12, 2009, in forum: C Programming
    Replies:
    21
    Views:
    1,061
    Keith Thompson
    Mar 14, 2009
  8. Replies:
    2
    Views:
    173
    J├╝rgen Exner
    Dec 1, 2007
Loading...