Skip to content

Instantly share code, notes, and snippets.

@dylanpyle
Created July 15, 2019 15:48
Show Gist options
  • Save dylanpyle/333484a1068177c933788b4f3bf0614f to your computer and use it in GitHub Desktop.
Save dylanpyle/333484a1068177c933788b4f3bf0614f to your computer and use it in GitHub Desktop.
Object Perf Testing
▸ node ~/Desktop/testbed.js
Completed test 1 in 26950ms
Completed test 2 in 14ms
function test1() {
let a = {};
for (let i = 0; i < 10000; i++) {
a = {
...a,
[`thing-${i}`]: 'hi'
};
}
}
function test2() {
const a = {};
for (let i = 0; i < 10000; i++) {
a[`thing-${i}`] = 'hi';
}
}
const s1 = Date.now();
test1();
console.log(`Completed test 1 in ${Date.now() - s1}ms`);
const s2 = Date.now();
test2();
console.log(`Completed test 2 in ${Date.now() - s2}ms`);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment