Psycho question

David C. Ullrich dullrich at
Wed Aug 6 21:52:56 CEST 2008

In article 
<8f0dc2a7-d3bd-4632-a282-9428c910088d at>,
 bearophileHUGS at wrote:

> David C. Ullrich:
> > Thanks. If I can get it installed and it works as advertised
> > this means I can finally (eventually) finish the process of
> > dumping MS Windows: the only reason I need it right now is for
> > the small number of Delphi programs I have for which straight
> > Python is really not adequate. Been not looking forward to
> > learning some C or Objective C (or whatever that Mac thing
> > is) - if I can just "accelerate" a few Python routines that'll
> > be great.
> To have better performance with Psyco you need low-level style code,
> generally not lazy, etc, and adopt some programming conventions, so
> you may have to rewrite your routines for max speed.

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

then convert back to a list or string or whatever outside
the accelerated function.

Surely something like _that_ is exactly what Psyco is going
to do well with, yes? (Ok, we're talking about image processing,
in cases where I can't figure out how to get PIL to do whatever
directly. So sometimes there will be double loops

for row in range(width):
  for col in range(height):
    do_something[row*width + col]

but at least for the things I can think of right now it
shouldn't get much worse than that.)

The things you mention below sound very interesting - I'm
going to try Psyco first because unless I'm missing something
I won't have to learn how to use it. Someday when it turns out
to be not good enough I'll be in touch...

> If some of your routines are too much slow there are many ways in
> Python to write faster modules, like Cython, Weave, Inline, Swig, SIP,
> ShedSkin, etc. For bioinformatics purposes I have found that Pyd + D
> language is good for me (I have tried Pyrex too few times, but I have
> lost my patience trying to track down in a jungle of ugly auto-
> generated C code where some reference count updates happen. Writing D
> code is hugely faster/better for me. Even writing a C extension for
> Python from scratch may be better for me because there aren't hidden
> things happening everywhere. I presume other people don't share this
> problems of mine because there are lot of people using Cython now).
> Bye,
> bearophile

David C. Ullrich

More information about the Python-list mailing list