Node.js process.hrtime.bigint() Method
Last Updated :
29 Jul, 2021
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.
index.js
var start_time = process.hrtime.bigint();
console.log( "Start Time:" , start_time);
setTimeout( function () {
console.log( "Execution time will be calculated...." );
var end_time = process.hrtime.bigint();
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
Javascript
var start_time = process.hrtime.bigint();
console.log( "Start Time:" , start_time);
setTimeout( function () {
var a = '45' ,
b = '40' ;
console.log( "Subtraction of two number is :" ,
(a - 0) - (b - 0));
var end_time = process.hrtime.bigint();
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
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...