The process.hrtime.bigint() method returns the current high-resolution real-time in nanoseconds as a bigint in NodeJS. It does not support an additional time argument because the difference can be computed directly by subtraction of the two bigints variables.
We used it to calculate the total time in the nanosecond between the process by subtracting the start time and end time.
Syntax:
process.hrtime.bigint();
Parameter: This function does not take any parameter.
Return Type: It returns bigint.
Example 1: Create an index.js file with the following code.
// Create a variable and call the // process.hrtime() function var start_time = process.hrtime.bigint();
// Print the Start time console.log( "Start Time:" , start_time);
// Make the add function setTimeout( function () {
console.log( "Execution time will be calculated...." );
// Create a variable and call the second
// process.hrtime() function
var end_time = process.hrtime.bigint();
// Print the Execution time
console.log( "End Time:" , end_time - start_time);
}, 2000); |
Run the index.js file using the following command:
node index.js
Output:
Start Time: 507990695929600n Execution time will be calculated.... End Time: 1005191900n
Example 2: Create an index.js file with the following code.
index.js
// Create a variable and call the // process.hrtime() function var start_time = process.hrtime.bigint();
// Print the Start time console.log( "Start Time:" , start_time);
// Make the add function setTimeout( function () {
// Create two variable
var a = '45' ,
b = '40' ;
// Print the Subtraction result
console.log( "Subtraction of two number is :" ,
(a - 0) - (b - 0));
// Create a variable and call the
// second process.hrtime() function
var end_time = process.hrtime.bigint();
// Print the Execution time
console.log( "End Time:" , end_time - start_time);
}, 1000); |
Output:
Start Time: 507818309465700n Subtraction of two number is : 5 End Time: 1008706600n
Reference: https://nodejs.org/api/process.html#process_process_hrtime_bigint