Writing a compiler (for scripts) and have found that FOR/NEXT loops use more (mathematically) then while/repeat loops...
Just a simple:
Works slower than a
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?
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?