Created
July 15, 2019 15:48
-
-
Save dylanpyle/333484a1068177c933788b4f3bf0614f to your computer and use it in GitHub Desktop.
Object Perf Testing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
▸ node ~/Desktop/testbed.js | |
Completed test 1 in 26950ms | |
Completed test 2 in 14ms |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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