I have a little snippet of node.js code in front of me that looks like this:
console.time(\"queryTime\");
doAsyncIOBoundThing(function(err, results) {
consol
Wouldn't this simple code work?
var labelWithTime = "label " + Date.now();
console.time(labelWithTime);
// Do something
console.timeEnd(labelWithTime);
Just use unique labels and it will be safe. That's why you use a label, to uniquely identify the start time.
As long as you don't accidentally use a label twice everything will work exactly as intended. Also note that node
has usually only one thread of execution.
Consider new NodeJS features as it has evolved too. Please look into:
process.hrtime()
& NodeJS's other performance API hooks:
https://nodejs.org/api/perf_hooks.html#perf_hooks_performance_timing_api