Re: utils.text.wrap is O(n^2)

2006-12-17 Thread Michael Radziej
Hi, somehow I kept interest in this and found a better solution. Splitting the whole text first into words is only the best way when the line width is close to the average word length. In the more typical cases you have multiple words per line, and then it's faster to process line by line by look

Re: utils.text.wrap is O(n^2)

2006-12-15 Thread Adrian Holovaty
On 12/15/06, Jacob Kaplan-Moss <[EMAIL PROTECTED]> wrote: > On 12/15/06 11:26 AM, Michael Radziej wrote: > > when I watched the presentation of GvR's Mondrian, his statement > > that django's word wrapper has quadratic behaviour made me take a > > look. Here's the result ... > > Awesome patch, Mic

Re: utils.text.wrap is O(n^2)

2006-12-15 Thread Jacob Kaplan-Moss
On 12/15/06 1:28 PM, John Lenton wrote: > I don't have a 100M text to test with, but I was wondering how changing that > to > > it = (m.group() for m in re.finditer(r'(\S+)', text)) > > would compare in both speed and memory? > (I expect it to use about half as much memory, due to not copying

Re: utils.text.wrap is O(n^2)

2006-12-15 Thread John Lenton
On 12/15/06, Michael Radziej <[EMAIL PROTECTED]> wrote: > > it = iter(text.split(' ')) I don't have a 100M text to test with, but I was wondering how changing that to it = (m.group() for m in re.finditer(r'(\S+)', text)) would compare in both speed and memory? (I expect it to use abo

Re: utils.text.wrap is O(n^2)

2006-12-15 Thread Jacob Kaplan-Moss
On 12/15/06 11:26 AM, Michael Radziej wrote: > when I watched the presentation of GvR's Mondrian, his statement > that django's word wrapper has quadratic behaviour made me take a > look. Here's the result ... Awesome patch, Michael. I tested your function a bit myself, made a small tweak for

utils.text.wrap is O(n^2)

2006-12-15 Thread Michael Radziej
Hi, when I watched the presentation of GvR's Mondrian, his statement that django's word wrapper has quadratic behaviour made me take a look. Here's the result ... def wrap(text, width): def _generator(): it = iter(text.split(' ')) for word in it: yield word