Skip to content

Instantly share code, notes, and snippets.

@sharechiwai
Created July 3, 2021 03:45
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
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