Time taken by function

OSCC · JavaScript, Function · Oct 22, 2020

Measures the time it takes for a function to execute.

const timeTaken = callback => {
  const r = callback();
  return r;
timeTaken(() => Math.pow(2, 10)); // 1024, (logged): timeTaken: 0.02099609375ms

Recommended snippets

  • Most performant function

    JavaScript, Function

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

  • Convert function from variadic

    JavaScript, Function

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

  • Juxtapose functions

    JavaScript, Function

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