سؤال

I have a python program that executes in about 1s. When executed under pypy it takes about 2s. However if I change my program from

import sys
from code import execute
if __main__:
    execute(sys.argv)

to

import sys
from code import execute
if __main__:
    for i in range(100):
        print i
        execute(sys.argv)

you can really se how pypy is "learning". The first runs takes about 2 seconds, then the executions goes faster and faster to end up taking about 0.15s.

Can I make pypy "remember" its optimization learning, so that the first run takes 0.15. As it looks now I cannot benefit from pypy, since my aplication will run many stand alone executions of the function execute.

هل كانت مفيدة؟

المحلول

No, that's basically not possible.

What is possible is to get the result you want with workarounds: for example, turn your program into a local "server" which waits for requests (done from executing a 5-lines script), and serves them by doing the job of execute(). It's certainly not the most elegant solution but it lets all the execute() be done by the same process, with (after a while) the same speed-ups that you measured.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top