Skip to main content

timeTaken

TS JS Deno

Measures the time taken by a function to execute.

Use console.time() and console.timeEnd() to measure the difference between the start and end times to determine how long the callback took to execute.

typescript
const timeTaken = (callback: Function) => {
const id = `timeTaken_${Date.now()}`;
console.time(id);
const r = callback();
console.timeEnd(id);
return r;
};
typescript
timeTaken(() => Math.pow(2, 10)); // 1024, (logged): timeTaken: 0.02099609375ms