[Tutor] Any suggestions for optimizing this code?

grouchy grouch at gmail.com
Mon Sep 19 07:16:36 CEST 2005

Hi John,

Thanks for that suggestion.

I tried replacing my matrix with a numpy array, and it was about 20% slower, 
but I just substituted one for the other, so that really isn't surprising. I 
didn't try with the built-in array, but I'm guessing that swapping out 
another container for lists would only have a chance of speeding it up by a 
constant amount, I think, since setting and getting list elements is O(1).

Having said that, I forgot arrays existed. I will take a look right now, and 
look at their methods, see if there is anything in there I can dig up to 
help above and beyond a new container.

I think, conceptually, I need to make the sliding window more efficient by 
not getting overlapping elements repeatedly, or maybe figuring out a way to 
skip the conversion from bits to integers. I tried storing as strings, and 
doing a join to get i.e. "110" and using that as a key to look up 1 or 0, 
but it was miserably slow :)

The ~15x speedup from psyco makes me think if there was a built-in function 
that could handle everything in one fell swoop with tight C code, that would 
probably speed it up a -lot-. But I haven't found anything like that for a 
sliding window type situation.

On 9/18/05, John Fouhy <john at fouhy.net> wrote:
> On 19/09/05, grouchy <grouch at gmail.com> wrote:
> > I've been playing with generating 1-D cellular automata, and this is the
> > fastest solution I've come up with so far.
> I haven't dug deep into your code --- but, I wonder if the array
> module might help?
> --
> John.
> _______________________________________________
> Tutor maillist - Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20050919/f99946e2/attachment.html

More information about the Tutor mailing list