timeTaken

JavaScript, Function

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

Recommended snippets

  • debouncePromise

    JavaScript, Function

    Creates a debounced function that returns a promise, but delays invoking the provided function until at least ms milliseconds have elapsed since the last time it was invoked. All promises returned during this time will return the same data.

  • mostPerformant

    JavaScript, Function

    Returns the index of the function in an array of functions which executed the fastest.

  • spreadOver

    JavaScript, Function

    Takes a variadic function and returns a function that accepts an array of arguments.