@vbarbarosh/node-helpers 3.55.0 → 3.56.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/perf_measure.js +16 -0
package/package.json
CHANGED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
const format_hrtime = require('./format_hrtime');
|
|
2
|
+
const perf_start = require('./perf_start');
|
|
3
|
+
|
|
4
|
+
async function perf_measure(fn, digits = 4)
|
|
5
|
+
{
|
|
6
|
+
const time0 = perf_start();
|
|
7
|
+
const out = {
|
|
8
|
+
value: await fn(),
|
|
9
|
+
};
|
|
10
|
+
const [u, v] = process.hrtime(time0);
|
|
11
|
+
out.time_ms = Math.round((u + v/1E9)*1000);
|
|
12
|
+
out.time_human = format_hrtime([u ,v], digits)
|
|
13
|
+
return out;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
module.exports = perf_measure;
|