Skip to content

Instantly share code, notes, and snippets.

@lukechilds
Created May 28, 2017 14:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lukechilds/538dde312de924a3854121193ea6c7c9 to your computer and use it in GitHub Desktop.
Save lukechilds/538dde312de924a3854121193ea6c7c9 to your computer and use it in GitHub Desktop.
const iterations = 100000000;
(() => {
console.time('Var While');
var iVarWhile = 0;
while (iVarWhile < iterations) {
iVarWhile += 2;
}
console.timeEnd('Var While');
})();
(() => {
console.time('Let While');
let iLetWhile = 0;
while (iLetWhile < iterations) {
iLetWhile += 2;
}
console.timeEnd('Let While');
})();
(() => {
console.time('Var For');
var iVarFor = 0;
for (iVarFor = 0; iVarFor < iterations; iVarFor += 2) {}
console.timeEnd('Var For');
})();
(() => {
console.time('Let For');
let iLetFor = 0;
for (iLetFor = 0; iLetFor < iterations; iLetFor += 2) {}
console.timeEnd('Let For');
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment