Files
30-seconds-of-code/snippets/time-taken.md
Angelos Chalaris 61200d90c4 Kebab file names
2023-04-27 21:58:35 +03:00

595 B

title, tags, cover, firstSeen, lastUpdated
title tags cover firstSeen lastUpdated
Time taken by function function shelf-plant 2017-12-17T17:55:51+02:00 2020-10-22T20:24:30+03:00

Measures the time it takes for 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.
const timeTaken = callback => {
  console.time('timeTaken');
  const r = callback();
  console.timeEnd('timeTaken');
  return r;
};
timeTaken(() => Math.pow(2, 10)); // 1024, (logged): timeTaken: 0.02099609375ms