[Tutor] Psyco Puzzle

Adam Bark adam.jtm30 at gmail.com
Fri Jan 12 15:16:59 CET 2007


On 11/01/07, Danny Yoo <dyoo at hkn.eecs.berkeley.edu> wrote:
>
>
>
> > Sometimes psyco speeds up a script by a factor of 10, and sometimes
> > it makes no difference at all. Here's a case where I fully expected
> > it to make a difference:
> > <http://www.rcblue.com/Python/Psyco_Puzzle.txt>. Whether using psyco
> > or not, this takes about 13 seconds on my computer. Why no difference?
>
> Psyco implements a Just-In-Time optimization approach, so I suspect that
> it does its analysis of a function only after that function has been run
> at least once --- otherwise, it has no run-time information on which it
> can use to analyze.
>
> In the code above, the code we want to optimize is fact().  However,
> fact() is only called one time in the whole program.  To test this
> hypothesis, it might be interesting to see if "priming" fact up will help.
>
> #############################################################
> if __name__ == '__main__':
>      printFact(5)            ## just to prime the function up
>      timeStart = time.time()
>      printFact(20000)
>      timeEnd = time.time()
>      print "Time was %.4g seconds" % (timeEnd - timeStart)
> #############################################################
>
>
>
> Furthermore, the magnitude of the numbers in the fact() code quickly get
> into bignum range, where psyco's optimizations probably won't be so
> effective.  In contrast, the primes code you have all deal with integers
> in the range of 32 bits.


I tested this myself and it looks like bignum is probably the slowdown here
without psyco:
20000! = 1.81e+77337
Time was 7.58 seconds
with psyco no priming:
20000! = 1.81e+77337
Time was 7.55 seconds
with psyco and priming:
5! = 1.20e+002
20000! = 1.81e+77337
Time was 7.591 seconds

there seems to be no difference with psyco or without even if you run the
function first.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070112/1768d599/attachment.html 


More information about the Tutor mailing list