-
-
Save sharechiwai/00256c8fd2c01c6849fb25f70782def5 to your computer and use it in GitHub Desktop.
code sample to show how to log javascript execution time
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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