💾benchmark(f)
Last updated
Was this helpful?
Last updated
Was this helpful?
Was this helpful?
JS ⟩ technique ⟩ decorator ⟩ 💾 benchmark(f)
replit:timed(f)
// ⭐ benchmark a function
function benchmark(f) {
return function(...args) {
console.log(`• Entering function: ${f.name}(${args}) ...`);
example
// test function
function addFrom1To(n) {
let sum = 0;
for (let i = 1; i <= n; i++) sum += i;
return sum;
}