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. Advertising

  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. 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. Collin VanDyck
    Replies:
    3
    Views:
    390
    Collin VanDyck
    Oct 27, 2003
  2. Sonia
    Replies:
    3
    Views:
    440
    Sonia
    Sep 1, 2003
  3. Replies:
    4
    Views:
    373
    Christian Bau
    Feb 11, 2006
  4. Replies:
    12
    Views:
    557
    ma740988
    Nov 10, 2006
  5. Replies:
    2
    Views:
    96
    J├╝rgen Exner
    Dec 1, 2007
Loading...

Share This Page