FOR/NEXT or WHILE?
BlitzMax Forums/BlitzMax Programming/FOR/NEXT or WHILE?
| ||
Writing a compiler (for scripts) and have found that FOR/NEXT loops use more (mathematically) then while/repeat loops... Just a simple: for x = 1 to 1000 next Works slower than a x=1 while x <= 1000 x=x+1 wend Now this is in my scripting laguage where I convert everything to a pcode after tokenizing it all. Then merely execute the (x86-like) pcode. I have tried to opimize it the best I can however keep coming to the same thing (that for/next loops are slower because they require slighly more math and line jumps). Is this the same for most languages as well (IE blitz, VB, etc)? Because in that case a slight optimization would be to change large loops (like updating verticies where the loop count can reach thousands) to a while/repeat rather than a for/next in some of the code I have used in the past. any thoughts? |
| ||
can't tell the same for me local is faster (36to 63in averange) the funny thing: without strict it is 4 times as fast as with strict?????? |
| ||
While/wend is quicket on my system but turn debug off and the difference is a lot smaller. I get the same slower rate with strict unless debug is turned off. |
| ||
ah your right in debug off both are the same speed again (12ms with strict) ... *note to my list: always test with and without debug due to strange implementation parts of BM* |
| ||
Debug off: With or without Strict they are both hovering around 30. Debug on: With Strict both took around 1150 or so. Very strange. Without Strict The ForNext loop took only 90 while the While loop took about 350. Weird results... |
| ||
with strict I should think local vars not global will be faster... |