ecj2 / momo

[NOT MAINTAINED / ABANDONED] A simple 2D game-making library written in JavaScript.
MIT License
1 stars 0 forks source link

Declare variables outside of loops #4

Closed ecj2 closed 6 years ago

ecj2 commented 6 years ago

Performance is slightly improved when declaring loop statement variables outside of loops rather than inside.

Example:

for (let i = 0; i < some_array.length; ++i) {

  // ...
}

Versus:

let i = 0;
let length = some_array.length;

for (i; i < length; ++i) {

  // ...
}

The second example is ever so slightly faster than the first one. All of Momo's loops should have their variables declared outside of the loops when appropriate to improve performance.