Skip to content

Instantly share code, notes, and snippets.

@lagden
Last active August 1, 2016 20:56
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save lagden/0ec5360c39e9a74783d6071a96c8c59e to your computer and use it in GitHub Desktop.
Benchmark cache length
function for1() {
'use strict';
const a = [];
for (let i = 0; i < 9999999; i++) {
a.push(i);
}
console.time('loop');
for (let c = 0; c < 1e3; c++) {
// ...
}
for (let i = 0, len = a.length; i < len; i++) {
// ...
}
console.timeEnd('loop');
}
for1();
function for2() {
'use strict';
const a = [];
for (let i = 0; i < 9999999; i++) {
a.push(i);
}
console.time('loop');
for (let c = 0; c < 1e3; c++) {
// ...
}
for (let i = 0; i < a.length; i++) {
// ...
}
console.timeEnd('loop');
}
for2();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment