Usage:
test([
() => expr1,
() => expr2,
// ...
() => exprN
], <how many times execute>);
function test (ways, times) { | |
ways.forEach((fn, k) => { | |
let total = 0; | |
for (let i = 0; i < times; i++) { | |
const start = performance.now(); | |
fn(); | |
const end = performance.now(); | |
total += end - start; | |
} | |
console.log(k + ': ' + (total / times).toFixed(5) + 'ms'); | |
}); | |
} |