Psycho question

David C. Ullrich dullrich at sprynet.com
Thu Aug 7 12:11:00 EDT 2008


In article <68SdnU6uHqxNjQfVnZ2dnUVZ_j6dnZ2d at speakeasy.net>,
 Erik Max Francis <max at alcyone.com> wrote:

> David C. Ullrich wrote:
> 
> > Thanks. I would have guessed that I'd want low-level style code;
> > that's the sort of thing I have in mind. In fact the only thing
> > that seems likely to come up right now is looping through an
> > array of bytes, modifying them. The plan is to use the array
> > module first to convert a string or a list to an array, outside
> > the accelerated part, then maybe do something like
> > 
> > for j in range(len(bytes)/3):
> >   g = (bytes[3*j] + bytes[3*j+1] + bytes[3*j+2])/3
> >   bytes[3*j] = bytes[3*j+1] = bytes[3*j+2] = g
> 
> If len(bytes) is large, you might want to use `xrange`, too.  `range` 
> creates a list which is not really what you need.

I didn't follow the explanation, but I read in the docs
that xrange can actually be slower under Psyco.

This morning I learned that my guess that array.array was
a good idea was correct: When I pass a list of ints to the
routine above it gets accelerated by a factor of between
10 and 15, while if I pass an array it's closer to 50.

This is so cool. Maybe I already said that.

-- 
David C. Ullrich



More information about the Python-list mailing list