Skip to content

Instantly share code, notes, and snippets.

@jastisriradheshyam
Last active August 13, 2020 16:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jastisriradheshyam/032dc605317ddc11cc6caf513ebb78a5 to your computer and use it in GitHub Desktop.
Save jastisriradheshyam/032dc605317ddc11cc6caf513ebb78a5 to your computer and use it in GitHub Desktop.
Time Measure of the code inside the node js (only use for benchmarking)
// Node.js Time measure for benchmarking
// Way One : in microseconds
var hrTime1 = process.hrtime();
// code
var hrTime1 = process.hrtime();
startP = hrTime[0] * 1000000 + hrTime[1] / 1000;
endP = hrTime1[0] * 1000000 + hrTime1[1] / 1000;
// Shows the time difference in micro second
console.log(endP - startP);
// Way Two : in nanoseconds
const start = process.hrtime();
// Code
const end = process.hrtime(start);
// Shows time in nano seconds
console.log("\n%d nanoseconds", end[0]*1e9 + end[1]);
// Way Three : In seconds
const start = process.hrtime();
// ....code to process
const end = process.hrtime(start);
console.log("\n%d seconds", end[0] + end[1] / 1000000000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment