Last active
August 13, 2020 16:27
-
-
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)
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
// 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