Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: Psycho question

Reply
Thread Tools

Re: Psycho question

 
 
bearophileHUGS@lycos.com
Guest
Posts: n/a
 
      08-06-2008
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.

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
 
Reply With Quote
 
 
 
 
bearophileHUGS@lycos.com
Guest
Posts: n/a
 
      08-06-2008
Erik Max Francis:
> If len(bytes) is large, you might want to use `xrange`, too. `range`
> creates a list which is not really what you need.


That's right for Python, but Psyco uses normal loops in both cases,
you can time this code in the two situations:

def foo1(n):
count = 0
for i in range(n):
count += 1
print count

def foo2(n):
count = 0
for i in xrange(n):
count += 1
print count

import psyco; psyco.full()
N = 100000000
#foo1(N)
foo2(N)

Bye,
bearophile
 
Reply With Quote
 
 
 
 
MRAB
Guest
Posts: n/a
 
      08-07-2008
On Aug 6, 8:52*pm, "David C. Ullrich" <(E-Mail Removed)> wrote:
> In article
> <(E-Mail Removed)>,
>
> *(E-Mail Removed) 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.
>

[snip]
A couple of points:

1. '/' with ints in Python 2.x returns an int, but from Python 3.x
it'll return a float. You're recommended to use '//' for int division.

2. 'range' can accept a step value, so you can rewrite that as:

for j in range(0, len(bytes), 3):
g = (bytes[j] + bytes[j+1] + bytes[j+2])//3 # I think you also
want // here
bytes[j] = bytes[j+1] = bytes[j+2] = g
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
RE: Psycho question Delaney, Timothy (Tim) Python 4 08-23-2008 05:22 PM
Psycho "Taylor Jimenez" is psycho Joe Jared, psychopath & SPEWS creator Nomen Nescio Computer Support 0 08-29-2006 05:40 PM
PSYCHO 1998 question Edward Holub DVD Video 1 05-19-2006 06:19 AM
PSYCHO 1998 question Edward Holub DVD Video 1 05-17-2006 03:04 AM
going psycho with microsoft generic error message... Sharon McCarty ASP .Net 1 11-13-2004 02:45 PM



Advertisments