[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.python

psyco question

miller.paul.w

2/3/2008 6:06:00 PM

Say I have a module with a function f in it, and I do

psyco.bind (f)

Is there any simple/easy/elegant way to retain a reference to the
*unoptimized* version of f so I can call them both and compare
performance? I've tried

f2 = copy.deepcopy (f)
psyco.bind (f)

but that doesn't work. Other ways I've thought of that might work
just seem silly (like putting the definition of f in a string, using
compile() to construct two code objects and using psyco.bind() on one
of them), so I'm wondering if there's a good way.

Thanks!

4 Answers

Marc 'BlackJack' Rintsch

2/3/2008 6:54:00 PM

0

On Sun, 03 Feb 2008 10:06:04 -0800, miller.paul.w wrote:

> Say I have a module with a function f in it, and I do
>
> psyco.bind (f)
>
> Is there any simple/easy/elegant way to retain a reference to the
> *unoptimized* version of f so I can call them both and compare
> performance?

What about `psyco.unbind()`?

Ciao,
Marc 'BlackJack' Rintsch

miller.paul.w

2/3/2008 7:19:00 PM

0

Thanks for your reply. It's been a while since I've used psyco, and
it seems either some functions have been added, or I've never needed
the other ones. :-)

For the record, it looks like

psyco.bind (f)
f2 = psyco.unproxy(f)

would leave me with an optimized f and a function f2 which is the
unoptimized version of f. In any case, it looks like I need to RTFM a
little more.

Thanks

Paul

Bearophile

2/3/2008 7:20:00 PM

0

miller:
> Is there any simple/easy/elegant way to retain a reference to the
> *unoptimized* version of f so I can call them both and compare
> performance?

A simple solution is to defer the optimization. That is test the
original code, call Psyco, then test it again:

def somefunc():
...

from time import clock
t0 = clock()
somefunc()
print clock() - t0
import psyco
psyco.bind(somefunc)
t0 = clock()
somefunc()
print clock() - t0

Bye,
bearophile

miller.paul.w

2/3/2008 8:03:00 PM

0

On Feb 3, 2:19 pm, bearophileH...@lycos.com wrote:

> simple solution is to defer the optimization. That is test the
> original code, call Psyco, then test it again:

I had thought of that, but it didn't really meet my requirements. I
might want the unoptimized function back at some point after I call
the unoptimized function. psyco.unbind() does the trick for this. :-)

Thanks for your reply