Created
July 21, 2021 22:47
-
-
Save nhuxhr/2998c1311338d3f0fd7236ec6a684fd3 to your computer and use it in GitHub Desktop.
Calculate Time taken by a Program to Execute in JavaScript
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
/** | |
* Calculate Time taken by a Program to Execute in JavaScript | |
* @author JSX Clan <jsxclan.dev@gmail.com> | |
*/ | |
// Starting time | |
const start = performance.now(); | |
// Some codes | |
for (let i = 1; i <= 10; i++) { | |
console.log(i) | |
} | |
// Ending time | |
const end = performance.now(); | |
console.log(`Runtime of the program is ${end - start} milliseconds.`); | |
// Output: Runtime of the program is 3.300000000745058 milliseconds. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment