Files
30-seconds-of-code/snippets/measure-time-taken-by-function.md
anbnyc 6254b49fb0 Remove stray open curly brace
Removes open curly brace in console.log in Measure time taken by function snippet
2017-12-11 14:40:53 -05:00

365 B

Measure time taken by function

Use performance.now() to get start and end time for the function, console.log() the time taken. First argument is the function name, subsequent arguments are passed to the function.

var timeTaken = (f,...args) => {
  var t0 = performance.now(), r = f(...args);
  console.log(performance.now() - t0);
  return r;
}