got a few questions before i get to the point->
does anyone know what kind of calculation goes into a logical operation when its executed?
is there a way to see the amount of calculation thats needed to execute a line of code?
or the amount of calculation thats needed to execute several lines of code?
is there a measuring method to give a line of code a value based on the amount of calculation it requires to complete its action? so i can compare smile.gif
now for what sparked my inquiries, i have two chunks of code and i think i know which one will executed faster but im still not sure.
this is the one that i think will execute quicker, but for this to happen i have to write about two times the amount of code. since i don't really understand how actionscript is compiled im unsure if the weight of the two loops will effect how quickly the code will be executed.
in this one there is logical operation to determine which loop to execute, the problem here is there is an extra logical operation and an expression and any other amount of calculation required to initiate a for loop:
var startVal=((amount/layers)*(j-1)==0)? 1:int((amount/layers)*(j-1))+1, end=(amount/layers)*j;
if(onoff){
for(;startVal<=end;startVal++){
currs[startVal]=((end*layerScale))*growthRatio;
targets[startVal]=currs[startVal]/growthRatio;
}
}else{
for(;startVal<=end;startVal++){
currs[startVal]=((end*layerScale));
targets[startVal]=currs[startVal]*growthRatio;
}
}
- var startVal=((amount/layers)*(j-1)==0)? 1:int((amount/layers)*(j-1))+1, end=(amount/layers)*j;
- if(onoff){
- for(;startVal<=end;startVal++){
- currs[startVal]=((end*layerScale))*growthRatio;
- targets[startVal]=currs[startVal]/growthRatio;
- }
- }else{
- for(;startVal<=end;startVal++){
- currs[startVal]=((end*layerScale));
- targets[startVal]=currs[startVal]*growthRatio;
- }
- }
this one i think will execute slower because in each iteration it has to execute an extra logical operation, but it gains from having one less loop in the code.
for(var startVal=((amount/layers)*(j-1)==0)? 1:int((amount/layers)*(j-1))+1, end=(amount/layers)*j;startVal<=end;startVal++){
if(onoff){
currs[startVal]=((end*layerScale))*growthRatio;
targets[startVal]=currs[startVal]/growthRatio;
}else{
currs[startVal]=((end*layerScale));
targets[startVal]=currs[startVal]*growthRatio;
}}
- for(var startVal=((amount/layers)*(j-1)==0)? 1:int((amount/layers)*(j-1))+1, end=(amount/layers)*j;startVal<=end;startVal++){
- if(onoff){
- currs[startVal]=((end*layerScale))*growthRatio;
- targets[startVal]=currs[startVal]/growthRatio;
- }else{
- currs[startVal]=((end*layerScale));
- targets[startVal]=currs[startVal]*growthRatio;
- }}
the first one ask's a question then loops, the second loops and ask's a question on each iteration but with the latter the total amount of written code is less.
thanks in advance for everyones help
