You might also want to use the Performance timing API in Node (and browsers) to use an API meant explicitly for measuring performance, rather than relying on Date.
Besides the more semantic API, you can have better resolution, and the API will deal with issues like a "later" call to Date
returning a value lower than an "earlier" call because someones messed with the system time.
The docs are pretty self-explanatory:
const { performance } = require('perf_hooks');
performance.mark('A');
doSomeLongRunningProcess(() => {
performance.mark('B');
performance.measure('A to B', 'A', 'B');
const measure = performance.getEntriesByName('A to B')[0];
console.log(measure.duration);
// Prints the number of milliseconds between Mark 'A' and Mark 'B'
});
OTOH, with regards to performance measurement, and especially latency/duration measurements, it's all in the eyes of the measurer. The most accurate way to do it is to measure in the client code and take into account things like network latency, intermediate processing, framework delays, etc.