Code speedup tips

Sean Richards someone at invalid.com
Fri Mar 7 22:04:33 EST 2003


On Tue, 04 Mar 2003 16:15:25 GMT, Carl Banks wrote:
 
> To exemplify, here is how I would convert Numeric data into an image
> using Python Imaging Library:
> 
>     img = Image.fromstring('L',(width,height),
>                            ((1-lattice)*255).astype(Int8).tostring())

That was good. In the original implementation of the code I first looked
at the author used a PhotoImage so I just followed his example. Using
the original code a 1 dimensional CA of length 1000 takes 80.5 secs and
does 499581 function calls to complete 500 steps. I re-implemented this
using the array slicing technique you covered earlier, bitwise operators,
optimised the way the image was created and used the PIL example above
to display the final image. Now takes 0.290 secs and 570 function calls
to do 500 steps of the 1000 long 1 dimensional CA.  
Would have taken me months to figure out all those cool tricks so thanks
Carl and everyone else who helped. 

Sean :)

-- 
+---------------------------------------------------------------+
| All spelling errors are intentional and are there to show new |
| and improved ways of spelling old words.                      |
+---------------------------------------------------------------+




More information about the Python-list mailing list