Skip to content

Instantly share code, notes, and snippets.

@cevek
Created October 18, 2018 21:32
Show Gist options
  • Save cevek/23ec40ce0d34609be0ea4aec7b1ac369 to your computer and use it in GitHub Desktop.
Save cevek/23ec40ce0d34609be0ea4aec7b1ac369 to your computer and use it in GitHub Desktop.
function abc(obj, prop) {
for (let j = 0; j < 1e7; j++) {
var x = obj[prop];
}
return x;
}
function abc2(obj) {
for (let j = 0; j < 1e7; j++) {
var x = obj.b;
}
return x;
}
var obj = {a: 1, b: 2, c: 3}
abc(obj, 'a');
abc(obj, 'b');
abc(obj, 'c');
console.time('perf');
abc(obj, 'b');
console.timeEnd('perf');
console.time('perf');
abc2(obj);
console.timeEnd('perf');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment