On 11/01/07, Danny Yoo <[EMAIL PROTECTED]> 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.
_______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor