From: Pete S. <pe...@vi...> - 2000-10-11 23:08:43
|
last night i was playing with more with optimizations and python. just thought i'd post the results since some of them might be interesting to some of you out there. first, using aliens, i did some side-by-side comparisons between C&SDL and Python&SDL. i took out all the audio from both c-aliens and py-aliens, then replaced the FPS idling with FPS counting. this was all on my Celeron-400, 128MB, TNT2-ultra i also locked the random seed for similar results each run (but couldn't get the same random results between C & Python) generally, the Python version ran about 65% the speed of the C version. So for general gaming, you should know you'll chop out 1/3 of the speed going with python. if you look at the big picture, just imagine your python processor is 1 year behind your C processor. of course, different parts of the code will have different ratios of performance. on the other hand, the Python version had about 1/2 the number of lines of code. it was worlds easier to work with and examine. for example, i was able to change the update algorithm for the Python version in about 5 lines of simple code. this gave me a 15% boost in speed. this would have been a lot more difficult on the C version. as far as getting the python version to work faster, i found the following results... disabling the (2b.0b2) garbage collection gave me no measurable speedup. cranking the sys.setcheckinterval() way up gave me about a 2% speedup, but it was hard to be measure for sure. (i found best results/value to be around 500, but in the end i don't think this tweaking is worthwhile) in a more roundabout tweaking, i tried to crank Windows process/thread scheduler to give me full priority. making minor changes (HIGH_PRIORITY_CLASS) made no noticeable difference, when i cranked things up (REALTIME_PRIORITY_CLASS, and TIME_CRITICAL) i saw a minor 3-4 fps improvement, but was astonished at how unresponsive the rest of the OS was. this type of tweaking is definitely NOT worth the costs on a Win98 system. (linux/NT may see better results? but not likely stellar) also, as usual, running python optimized (-O, -OO) netted no noticeable performance boost. (maybe 1-2 fps) in the end, it seems there's no such thing as a free speedup. there's not even very good ways to tweak python code to get it to run faster. the best advice i've found for optimizing pysdl code is... if you have several refernces to the same global/builtin variable in one routine, make a local reference to it and call that instead. it will only be in tight loops you see the fruit of this change, but local variables are quicker than global/builtin ones. this mainly applies to function calls use Numeric python find a better algorithm well, sadly i have nothing exciting to report with my latest testing, but the information does answer questions, and hopefully keeps other folks on the right track. a good page for general python optimization-ness is here http://www.musi-cal.com/~skip/python/fastpython.html |