473,480 Members | 2,325 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Psycho question

Just heard about Psycho. I've often wondered why someone
doesn't make something that does exactly what Psycho does - keen.

Silly question: It's correct, is it not, that Psycho doesn't
actually modify the Python installation, except by adding a
module or two (so that code not using Psycho is absolutely
unaffected)?

Thanks,

--
David C. Ullrich
Aug 5 '08 #1
11 2082
David C. Ullrich wrote:
Just heard about Psycho. I've often wondered why someone
doesn't make something that does exactly what Psycho does - keen.

Silly question: It's correct, is it not, that Psycho doesn't
actually modify the Python installation, except by adding a
module or two (so that code not using Psycho is absolutely
unaffected)?
That's correct. Hi, David!

--
Erik Max Francis && ma*@alcyone.com && http://www.alcyone.com/max/
San Jose, CA, USA && 37 18 N 121 57 W && AIM, Y!M erikmaxfrancis
Longevity has its place. But I'm not concerned about that now.
-- Dr. Martin Luther King, Jr.
Aug 5 '08 #2
In article <w_******************************@speakeasy.net> ,
Erik Max Francis <ma*@alcyone.comwrote:
David C. Ullrich wrote:
Just heard about Psycho. I've often wondered why someone
doesn't make something that does exactly what Psycho does - keen.

Silly question: It's correct, is it not, that Psycho doesn't
actually modify the Python installation, except by adding a
module or two (so that code not using Psycho is absolutely
unaffected)?

That's correct. Hi, David!
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.

Tentatively a very happy camper. See ya.

--
David C. Ullrich
Aug 6 '08 #3
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
Aug 6 '08 #4
In article
<8f**********************************@e53g2000hsa. googlegroups.com>,
be************@lycos.com 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
Aug 6 '08 #5
In article <du****************************@text.giganews.com> ,
"David C. Ullrich" <du******@sprynet.comwrote:
In article
<8f**********************************@e53g2000hsa. googlegroups.com>,
be************@lycos.com 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?
teehee. Downloaded Psyco. The install actually worked.
Tried exactly what's above with a list of 3 million ints.
Didn't time it carefully, seemed to take about two seconds.
Ran it again, in case the second run would be faster for some reason.
Second was about the same.

Said "import psyco", etc. Ran the routine again, it returned
in _no_ time, perceptually.

This is so cool. Gonna find out whether a decorator that
returns the accelerated function works, just for the fun
of deciding what the name should be: @cool? @wheee?
@wow? @dontblinkyoullmissit?
>(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
Aug 6 '08 #6
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.

--
Erik Max Francis && ma*@alcyone.com && http://www.alcyone.com/max/
San Jose, CA, USA && 37 18 N 121 57 W && AIM, Y!M erikmaxfrancis
You and I / We've seen it all / Chasing our hearts' desire
-- The Russian and Florence, _Chess_
Aug 6 '08 #7
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
Aug 6 '08 #8
In article <68******************************@speakeasy.net> ,
Erik Max Francis <ma*@alcyone.comwrote:
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
Aug 7 '08 #9
On Aug 6, 8:52*pm, "David C. Ullrich" <dullr...@sprynet.comwrote:
In article
<8f0dc2a7-d3bd-4632-a282-9428c9100...@e53g2000hsa.googlegroups.com>,

*bearophileH...@lycos.com 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
Aug 7 '08 #10
In article
<de**********************************@p25g2000hsf. googlegroups.com>,
MRAB <go****@mrabarnett.plus.comwrote:
On Aug 6, 8:52*pm, "David C. Ullrich" <dullr...@sprynet.comwrote:
In article
<8f0dc2a7-d3bd-4632-a282-9428c9100...@e53g2000hsa.googlegroups.com>,

*bearophileH...@lycos.com 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
Not the issues I expected to be worrying about here, but thanks.

Of course the range(0, len(bytes), 3) is more elegant, and
it's probably faster in Python, but curiously it's much
slower under Psyco! Otoh xrange(0, len(bytes), 3) becomes
pretty fast again. So I conjecture that Psyco compiles
"for j in range(l)" just as a loop but actually constructs
an array for range(0, l, step).

Also very curiously, // inside the loop is much slower than
/ here (under Psyco). This one I'm not going to guess why...

Honest:

"""Ah - psyco does work with exec if the import psyco,
etc is inside the code being executed (right now it's
in its own namespace, hence a fresh import each time
- check whether this works with exec in default
namespaces).

Ie, this script works fine in DUShell:"""

from psyco import proxy, bind

def f(b):
for j in range(len(b)/3):
i = 3*j
g = (b[i] + b[i+1] + b[i+2])/3
b[i] = b[i+1] = b[i+2] = g

g = proxy(f)

def h(b):
for j in range(0,len(b),3):
#for i in range(len(b)/3):
#j = 3*i
g = (b[j] + b[j+1] + b[j+2])//3
b[j] = b[j+1] = b[j+2] = g
bind(h)
from time import time

fs = {'f':f, 'g':g, 'h':h}

def t(f,b):
F = fs[f]
st = time()
F(b)
et = time()
print "%s: %s" % (f, et-st)

b = range(30000)

from array import array
c = array('i',b)
t('f',c)
t('g',c)
t('h',c)
t('f',c)
t('g',c)
t('h',c)

outputs

f: 0.0158488750458
g: 0.000610113143921
h: 0.00200295448303
f: 0.0184948444366
g: 0.000257015228271
h: 0.00116610527039

--
David C. Ullrich
Aug 7 '08 #11
For the benefit of those trying to find, download, and import the
module, its name is psyco (no 'h'), not psycho .
http://psyco.sourceforge.net/

Aug 8 '08 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
4990
by: Stevey | last post by:
I have the following XML file... <?xml version="1.0"?> <animals> <animal> <name>Tiger</name> <questions> <question index="0">true</question> <question index="1">true</question> </questions>
7
2623
by: nospam | last post by:
Ok, 3rd or is it the 4th time I have asked this question on Partial Types, so, since it seems to me that Partial Types is still in the design or development stages at Microsoft, I am going to ask...
3
3053
by: Ekqvist Marko | last post by:
Hi, I have one Access database table including questions and answers. Now I need to give answer id automatically to questionID column. But I don't know how it is best (fastest) to do? table...
10
3386
by: glenn | last post by:
I am use to programming in php and the way session and post vars are past from fields on one page through to the post page automatically where I can get to their values easily to write to a...
10
3677
by: Rider | last post by:
Hi, simple(?) question about asp.net configuration.. I've installed ASP.NET 2.0 QuickStart Sample successfully. But, When I'm first start application the follow message shown. ========= Server...
53
4011
by: Jeff | last post by:
In the function below, can size ever be 0 (zero)? char *clc_strdup(const char * CLC_RESTRICT s) { size_t size; char *p; clc_assert_not_null(clc_strdup, s); size = strlen(s) + 1;
56
4687
by: spibou | last post by:
In the statement "a *= expression" is expression assumed to be parenthesized ? For example if I write "a *= b+c" is this the same as "a = a * (b+c)" or "a = a * b+c" ?
2
4249
by: Allan Ebdrup | last post by:
Hi, I'm trying to render a Matrix question in my ASP.Net 2.0 page, A matrix question is a question where you have several options that can all be rated according to several possible ratings (from...
3
2534
by: Zhang Weiwu | last post by:
Hello! I wrote this: ..required-question p:after { content: "*"; } Corresponding HTML: <div class="required-question"><p>Question Text</p><input /></div> <div...
0
6915
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7054
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6750
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
6993
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5353
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4794
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4493
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3003
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
193
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.