Open rspilk opened 10 years ago
I was able to improve the speed about 3x without any changes except for using numpy's randint function instead of random
change import random
to from numpy import random
make sure numpy is installed.
I was told using random.choice() also helps performance, but haven't tested.
On Wednesday, March 5, 2014, tspilk notifications@github.com wrote:
I was able to improve the speed about 3x without any changes except for using numpy's randint function instead of random
change import random
to from numpy import random
make sure numpy is installed.
Reply to this email directly or view it on GitHubhttps://github.com/jmcrosa/Anarchy_TPP_Ecruteak/issues/3#issuecomment-36771571 .
Jose Crosa
I just pushed an update that addresses some of these issues. I did not use numpy, however I did change random.randint() to random.randchoice(), which I think it's more efficient. Also added an Odds class that takes over the states of the odds, thus reducing the amount of times the elif is executed. Can you see if the performance is better?
Using the cProfile module, we can see where a majority of the time is spent during the program execution. If one command takes way more than anything else, improving the time it takes to do that command will drastically increase the simulation speed.
I ran the program for 84.16s and here is the output I got:
it shows that 13151163 29.703 0.000 33.302 0.000 random.py:173(randrange) 13151163 11.610 0.000 44.912 0.000 random.py:236(randint) 13151163 20.164 0.000 65.076 0.000 twitchplays.py:34(getMove)
are your big time hogs. Since randint is used for getMove, it makes sense. Your getMove is what is holding back the massive speed. Since this is all using fixed odds in a big if statement, it should be possible to optimize this through restructuring or even forcing a c-optimized switch statement. I will see what I can do.