I want to send 2000 db requests via node end measure the time of each request. something like this:
var getKey = function(key, i) {
console.time(i);
client.getKey(key, function(val) {
console.timeEnd(i);
}
}
for(var i = 0; i < 2000; i ++) {
getKey(keys[i], i);
}
The problem is it doesn't measure well beacouse of node.it gets to the start time and then waits(because its one thread) - so each measure gets more ms than it really should. How can I fix it? i'm a bit new to NodeJS. thanks.
Granular performance functionality is available with
process.hrtime(). Tom Pawlak has a great blog post titled, "How to Measure Execution Time in Node.js", which explains the best practices associated with measuring execution time of your node.js code:Please let me know if you have any questions!