Skip to content

Instantly share code, notes, and snippets.

@burnpiro burnpiro/index.js
Created Nov 7, 2019

Embed
What would you like to do?
Performance test eval multi function call JS
eval(`
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
You can’t perform that action at this time.