Created
November 7, 2019 14:55
-
-
Save burnpiro/56be270ac032924faf48824e08995687 to your computer and use it in GitHub Desktop.
Performance test function call JS
This file contains hidden or 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
const startT1 = Date.now(); | |
const N = 10000; | |
let f = { tmp: 3, tmp2: 3, tmp3: 3, tmp4: 3, tmp5: 3, a: 'Gandalf', b: 'The Grey' }; | |
let f2 = { tmp: 3, tmp2: 3, tmp3: 3, tmp4: 3, tmp5: 3, a: 'Jack', b: 'Sparrow' }; | |
let f3 = { tmp: 3, tmp2: 3, tmp3: 3, tmp4: 3, tmp5: 3, a: 'Charles', b: 'Xavier' }; | |
let f4 = { tmp: 3, tmp2: 3, tmp3: 3, tmp4: 3, tmp5: 3, a: 'Frodo', b: 'Baggins' }; | |
let f5 = { tmp: 3, tmp2: 3, tmp3: 3, tmp4: 3, tmp5: 3, a: 'Legolas', b: 'Thranduilion' }; | |
let f6 = { tmp: 3, tmp2: 3, tmp3: 3, tmp4: 3, tmp5: 3, a: 'Indiana', b: 'Jones' }; | |
function test(obj) { | |
let result = ''; | |
for (let i = 0; i < N; i += 1) { | |
result += obj.a + obj.b; | |
} | |
return result; | |
} | |
for(let i = 0; i < N; i += 1) { | |
test(f); | |
test(f2); | |
test(f3); | |
test(f4); | |
test(f5); | |
test(f6); | |
} | |
console.log("test with one shape:", Date.now() - startT1, "ms."); | |
const used = process.memoryUsage().heapUsed / 1024 / 1024; | |
console.log(`The script uses approximately ${Math.round(used * 100) / 100} MB`); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment