Time taken by function

JavaScript, Function · Oct 22, 2020

Measures the time it takes for a function 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

More like this

  • Most performant function

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

    JavaScript, Function · Oct 21, 2020

  • Convert function from variadic

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

    JavaScript, Function · Jun 13, 2021

  • Juxtapose functions

    Takes several functions as argument and returns a function that is the juxtaposition of those functions.

    JavaScript, Function · Oct 20, 2020