psyco question

M

miller.paul.w

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!
 
M

Marc 'BlackJack' Rintsch

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
 
M

miller.paul.w

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
 
B

bearophileHUGS

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
 
M

miller.paul.w

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,678
Members
48,796
Latest member
Greg L.

Latest Threads

Top