How to time a function in JavaScript

Performance
By Jad Joubran · 
Last updated Mar 14, 2018
function foo() {
  // do stuff
}

const start = performance.now();
foo();
const end = performance.now();

console.log(`Call to ${foo.name} took ${end - start} ms.`);
Call to foo took x ms