How to auto-optimize a Python application?
I have a complex Python server application, which is batch based. I want this application to work as fast a possible. In this application there are probably something like 100 integer constants that somehow affect the performance of the application. These could be something like the initial size of a dictionary, setting memory constraints of external programs.
What I would like to do is to enable an optimizer program to modify these 100 integer values and run thousands of tests over night and figure out what set of parameters would have the Python program finish in the shortest time.
Does such a thing exist? I imagine that I could b开发者_开发知识库uild this somehow using the EXEC statement and the replace function to modify the integers.
If the effect of each variable is independent of the other variables, you can feasibly do this using a script to optimize each variable in turn... if each variable can assume k values and there are n variables, this is O(nk). If the variables may affect each other's effect on performance is completely arbitrary ways, you would have to enumerate and test all O(k^n) assignments. If you're somewhere in between, it makes describing an algorithm a little harder.
Regarding the mechanics, as soon as you figure out what configurations are meaningful (as in above), a simple script/program using e.g. exec or time should work. Even if a tool did exist, you'd still need an answer to the above to avoid the brute-force O(k^n) solution... or recognize that this is the best you can do.
精彩评论