Optimizing JavaScript For Execution Speed
2 отговора
94 прегледа
Optimizing JavaScript For Execution Speed
Пак по темата с оптимизациите.
[линк]

От неизбежното се възмущава само този, който е неразумен.
[линк]
От неизбежното се възмущава само този, който е неразумен.
Re: Optimizing JavaScript For Execution Speed
Е това ме уби... Някой да ме/ни светне?
Reverse Loops
Reversing loop conditions so that they count down instead of up can double the speed of loops. Counting down to zero with the decrement operator (i--) is faster than counting up to a number of iterations with the increment operator (i++). So instead of this (see Listing 10.9):
Listing 10.9 A Normal for Loop Counts Up
Do this (see Listing 10.10):
Listing 10.10 A Reversed for Loop Counts Down
Има три вида хора. Част от проблема, част от решението и част от пейзажа.
Reverse Loops
Reversing loop conditions so that they count down instead of up can double the speed of loops. Counting down to zero with the decrement operator (i--) is faster than counting up to a number of iterations with the increment operator (i++). So instead of this (see Listing 10.9):
Listing 10.9 A Normal for Loop Counts Up
function loopNormal() {
for (var i=0;i<iter;i++) {
// do something here
}
}
Do this (see Listing 10.10):
Listing 10.10 A Reversed for Loop Counts Down
function loopReverse() {
for (var i=iter;i>0;i--) {
// do something here
}
}
Има три вида хора. Част от проблема, част от решението и част от пейзажа.
Всъщност не е проблема...
в цикъла, ами в сравненията. Според доста хора сравнението с нула било по-бързо отколкото с което и да е друго число, още по-малко променлива. Също се смята че ++i е по-бързо от i++, само дето правят различни неща
Ако пък избягвате цикли с for ще е най-добре
There are three determined states the cat could be in: Alive, Dead, and Bloody Furious.
Ако пък избягвате цикли с for ще е най-добре
There are three determined states the cat could be in: Alive, Dead, and Bloody Furious.