Node.js process.hrtime( ) Method
The process.hrtime() method to measure code execution time which returns array which include current high-resolution real time in a [seconds, nanoseconds]. We measure the code execution time by providing the time returned by the first process.hrtime() call as a parameter in the second process.hrtime() call.
The Advantage of process.hrtime() is it measures time very accurate execution time which last less than a millisecond.
Parameter: This method accept a single parameter as mentioned above an described below.
- time : The time is an optional parameter that must be the result of a previous process.hrtime() call to difference with the current time.
Return Type: It returns an array of 2 ints. The 1. int contains the seconds and the 2. int the nanoseconds. These times are relative to an arbitrary time in the past, and not related to the time of day.
Time in millisecond is: 218394926745.5
Output: It means 1 second and 8779100 nanoseconds from start to end time is taken.
Start Time: [ 682340, 452477300 ] Add of two number is : 90 End Time: [ 1, 8779100 ]
Output: It means 1 second and 10987200 nanoseconds from start to end time is taken.
Start Time: [ 682865, 516565300 ] Execution time will be calculated for printing this message.... End Time: [ 1, 10987200 ]
Reference Taken : https://nodejs.org/api/process.html#process_process_hrtime_time