Re: timing puzzle

2007-11-16 Thread Neil Cerutti
On 2007-11-16, Robin Becker <[EMAIL PROTECTED]> wrote: > Neil Cerutti wrote: > ... > > > see why. >> >> You are no longer making m copies of active_nodes. > > my profiling indicated that the main problem was the removes. Yeah, I should've added, "for one thing." I'm glad Chris correctly poi

Re: timing puzzle

2007-11-16 Thread Robin Becker
Neil Cerutti wrote: ... see why. > > You are no longer making m copies of active_nodes. my profiling indicated that the main problem was the removes. > > > When you have to make many deletions from the middle of a > sequence, you would normally choose a linked list. Python doe

Re: timing puzzle

2007-11-16 Thread Robin Becker
Chris Mellon wrote: > > remove() does a linear search to find the item to remove, so it's O(n) > + the actual deletion. Append() is amortized O(1) (overcommit). If you > delete by index instead: > for idx, node in active_nodes: > if cond: > del active_nodes[idx] > > that's what I

Re: timing puzzle

2007-11-16 Thread Neil Cerutti
On 2007-11-16, Neil Cerutti <[EMAIL PROTECTED]> wrote: > Instead, filter your list. It looks like you can't use filter > directly, so just do it manually. > >for i in xrange(m): >... >saved_nodes = [] >for A in active_nodes[:]: I meant to remove the slice. That line

Re: timing puzzle

2007-11-16 Thread Neil Cerutti
On 2007-11-16, Robin Becker <[EMAIL PROTECTED]> wrote: > I'm trying to get my head round a timing puzzle I find whilst > optimizing A Kuchling's version of the Knuth line splitting > algorithm from the oedipus project. The puzzle is as follows in > highly abstract form

Re: timing puzzle

2007-11-16 Thread Chris Mellon
On Nov 16, 2007 12:42 PM, Robin Becker <[EMAIL PROTECTED]> wrote: > I'm trying to get my head round a timing puzzle I find whilst optimizing A > Kuchling's version of the Knuth line splitting algorithm from the oedipus > project. The puzzle is as follows in h

timing puzzle

2007-11-16 Thread Robin Becker
I'm trying to get my head round a timing puzzle I find whilst optimizing A Kuchling's version of the Knuth line splitting algorithm from the oedipus project. The puzzle is as follows in highly abstract form (here active_nodes is a list of objects kept in a sorted order, but th