Skip to content

Instantly share code, notes, and snippets.

@nhuxhr
Created July 21, 2021 22:47
Show Gist options
  • Save nhuxhr/2998c1311338d3f0fd7236ec6a684fd3 to your computer and use it in GitHub Desktop.
Save nhuxhr/2998c1311338d3f0fd7236ec6a684fd3 to your computer and use it in GitHub Desktop.
Calculate Time taken by a Program to Execute in JavaScript
/**
* 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