Skip to content

Instantly share code, notes, and snippets.

@sr9yar
Created April 10, 2025 08:48
Show Gist options
  • Save sr9yar/9af9fc08d959a5140bc3c3126ee43b78 to your computer and use it in GitHub Desktop.
Save sr9yar/9af9fc08d959a5140bc3c3126ee43b78 to your computer and use it in GitHub Desktop.
Simple code execution measurement
const start = new Date();
const hrStart = process.hrtime();
// process.hrtime();
// https://nodejs.org/api/process.html#processhrtimetime
// [seconds, nanoseconds]
setTimeout(() => {
const end = new Date() - start;
const hrEnd = process.hrtime(hrStart);
console.log(`Exec time: ${end}`);
console.log(`Exec time hr: ${hrEnd[0]} sec and ${hrEnd[1] / 1000000} ms`);
}, Math.ceil(Math.random() * 3000));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment