Skip to content

Instantly share code, notes, and snippets.

@sharechiwai
Created July 3, 2021 03:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sharechiwai/00256c8fd2c01c6849fb25f70782def5 to your computer and use it in GitHub Desktop.
Save sharechiwai/00256c8fd2c01c6849fb25f70782def5 to your computer and use it in GitHub Desktop.
code sample to show how to log javascript execution time
// created a delay function to simulate a slow process
const delay = ms => new Promise(res => setTimeout(res, ms));
// create a time to log full execution time
console.time('full');
// create a time to log the 3s process
console.time('log 3s');
await delay(3000);
console.log('3s');
console.timeEnd('log 3s');
console.time('log 5s');
await delay(5000);
console.log('5s');
console.timeEnd('log 5s');
console.time('log 10s');
await delay(10000);
console.log('10s');
console.timeEnd('log 10s');
// print the full execution time
console.timeEnd('full');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment