A year or two ago I wrote a mail with some tricks that would reduce the execution time of your code in Hollywood. The subject interests me, and I keep looking for improvements of this type.
While looking at ways of optimizing the code in one of my programs I did a small test on some appearently straightforward code that surely must be in use in many places. To my surprise a change in this simple code gave a considerable speed increase. The test was made on a 733MHz SAM-Flex.
I use the code for managing the movement of a cursor in a textbox, but similar code can be found in games where an object is moved this or that way depending on a condition. In the example I have just used the value True to represent the test.
My testexample ran as follows
Code: Select all
starttimer(1)
for i=1 to 100000
if true
v=v+1
else
v=v-1
endif
next
nprint(gettimer(1),v)
waitleftmouse
end
It is well known, that changing variables into local variables will speed up things. If I add the line...
Code: Select all
Local i,v=0,0
Now replace this code:
Code: Select all
if true
v=v+1
else
v=v-1
endif
Code: Select all
v=v+1
if True Then v=v-2
Another observation is that code seems to execute faster when run from a window than if using full-screen mode. It is just a few percent and consistent no matter which window size you use - even if you set the window to the same as the full screen size (1920x1200 in my case). I added a Wait(100) statement before starting the timer and running the test loop. So the screen setup should not be a factor as far as I can see. If I don't do this it does affect the result.
regards Jesper