@@ -1016,33 +1016,37 @@ Android)
1016
1016
added: v0.7.6
1017
1017
-->
1018
1018
1019
- The ` process.hrtime() ` method returns the current high-resolution real time in a
1020
- ` [seconds, nanoseconds] ` tuple Array. ` time ` is an optional parameter that must
1021
- be the result of a previous ` process.hrtime() ` call (and therefore, a real time
1022
- in a ` [seconds, nanoseconds] ` tuple Array containing a previous time) to diff
1023
- with the current time. These times are relative to an arbitrary time in the
1024
- past, and not related to the time of day and therefore not subject to clock
1025
- drift. The primary use is for measuring performance between intervals.
1019
+ * ` time ` {Array} The result of a previous call to ` process.hrtime() `
1020
+ * Returns: {Array}
1021
+
1022
+ The ` process.hrtime() ` method returns the current high-resolution real time
1023
+ in a ` [seconds, nanoseconds] ` tuple Array, where ` nanoseconds ` is the
1024
+ remaining part of the real time that can't be represented in second precision.
1026
1025
1027
- Passing in the result of a previous call to ` process.hrtime() ` is useful for
1028
- calculating an amount of time passed between calls:
1026
+ ` time ` is an optional parameter that must be the result of a previous
1027
+ ` process.hrtime() ` call to diff with the current time. If the parameter
1028
+ passed in is not a tuple Array, a ` TypeError ` will be thrown. Passing in a
1029
+ user-defined array instead of the result of a previous call to
1030
+ ` process.hrtime() ` will lead to undefined behavior.
1031
+
1032
+ These times are relative to an arbitrary time in the
1033
+ past, and not related to the time of day and therefore not subject to clock
1034
+ drift. The primary use is for measuring performance between intervals:
1029
1035
1030
1036
``` js
1037
+ const NS_PER_SEC = 1e9 ;
1031
1038
var time = process .hrtime ();
1032
1039
// [ 1800216, 25 ]
1033
1040
1034
1041
setTimeout (() => {
1035
1042
var diff = process .hrtime (time);
1036
1043
// [ 1, 552 ]
1037
1044
1038
- console .log (` Benchmark took ${ diff[0 ] * 1e9 + diff[1 ]} nanoseconds` );
1045
+ console .log (` Benchmark took ${ diff[0 ] * NS_PER_SEC + diff[1 ]} nanoseconds` );
1039
1046
// benchmark took 1000000527 nanoseconds
1040
1047
}, 1000 );
1041
1048
```
1042
1049
1043
- Constructing an array by some method other than calling ` process.hrtime() ` and
1044
- passing the result to process.hrtime() will result in undefined behavior.
1045
-
1046
1050
1047
1051
## process.initgroups(user, extra_group)
1048
1052
<!-- YAML
0 commit comments