Skip to content

Instantly share code, notes, and snippets.

@nonlogos
Created December 10, 2017 17:15
Show Gist options
  • Save nonlogos/61cb64ffbf54e7891f9b723d36899608 to your computer and use it in GitHub Desktop.
Save nonlogos/61cb64ffbf54e7891f9b723d36899608 to your computer and use it in GitHub Desktop.
Using console log to log out time it takes to run a function

To set up the time log function

const timeIt = (label, fn) => {
  console.time(label);
  fn();
  console.timeEnd(label);
}

Example to use it

const arrayOfRandoms = randomCeil => length => Array.from({length: length}, (v, i) => Math.floor(Math.random() * randomCeil));

const arrOfThousand = arrayOfRandoms(100)(1000);

// use time log
timeIt('thousand - map', () => {
  const resultFrom1000 = arrOfThousand
    .map(val => val * 3);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment