invoke
This is the legacy version of {@link process.hrtime.bigint()} before bigint was introduced in JavaScript.
The process.hrtime()
method returns the current high-resolution real time in a [seconds, nanoseconds]
tuple Array
, where nanoseconds
is the remaining part of the real time that can't be represented in second precision.
time
is an optional parameter that must be the result of a previous process.hrtime()
call to diff with the current time. If the parameter passed in is not a tuple Array
, a TypeError will be thrown. Passing in a user-defined array instead of the result of a previous call to process.hrtime()
will lead to undefined behavior.
These times are relative to an arbitrary time in the past, and not related to the time of day and therefore not subject to clock drift. The primary use is for measuring performance between intervals:
const { hrtime } = require('node:process');
const NS_PER_SEC = 1e9;
const time = hrtime();
// [ 1800216, 25 ]
setTimeout(() => {
const diff = hrtime(time);
// [ 1, 552 ]
console.log(`Benchmark took ${diff[0] * NS_PER_SEC + diff[1]} nanoseconds`);
// Benchmark took 1000000552 nanoseconds
}, 1000);
Since
0.7.6
Parameters
The result of a previous call to process.hrtime()