Talk:While
Revision as of 17:10, 7 August 2013 by Strife Onizuka (talk | contribs)
How is it that a do loop is faster than a while loop? I wrote some code to test this and they look equal to me.Lowrez Resident 14:58, 7 August 2013 (PDT)
- The while loop in the LSO compiler produces the following output for the various loop types. That is unless they decided to do a little optimizing (they were NEVER going to optimize LSO).
//while loop test: if(condition)false jump end; //6 bytes (1 for bytecode, 1 for type designation for conditional, 4 bytes for jump offset). //loop body goes here jump test;//5 bytes (1 for bytecode, 4 bytes for jump offset). end: //do-while loop start: //loop body goes here if(condition)true jump start;//6 bytes (1 for bytecode, 1 for type designation for conditional, 4 bytes for jump offset).
- As you can see, for each loop iteration the while loop executes two bytecodes while the do-while executes only one. Of course LL could have fixed this by rewriting the while as follows:
jump test;//5 bytes (1 for bytecode, 4 bytes for jump offset). start: //loop body goes here test: if(condition)true jump start;//6 bytes (1 for bytecode, 1 for type designation for conditional, 4 bytes for jump offset).