UNPKG

2.02 kBJavaScriptView Raw
1// const convertHrtime = require(`convert-hrtime`)
2// const _ = require(`lodash`)
3// const treeify = require(`treeify`)
4// const ss = require(`simple-statistics`)
5// let root = {
6// ROOT: process.hrtime(),
7// }
8// const profile = ({ name, start, parent }) => {
9// const span = convertHrtime(process.hrtime(start))
10// let path = parent ? `${parent}.${name}` : name
11// let currentValue = _.get(root, path)
12// if (_.isObject(currentValue)) {
13// path = `${path}.ROOT`
14// currentValue = _.get(root, path)
15// }
16// const newValue = currentValue
17// ? currentValue + span.milliseconds
18// : span.milliseconds
19// if (name === `run-query`) {
20// console.log({
21// path,
22// span: span.milliseconds,
23// newValue,
24// })
25// }
26// root = _.set(root, path, newValue)
27// }
28// global._PROFILE = profile
29// module.exports = profile
30// const labelify = (object, rootValue) =>
31// _.mapKeys(object, (value, key, o) => {
32// const currentValue = _.isObject(value) ? value.ROOT : value
33// return `${key}: ${currentValue}ms | ${(
34// (currentValue / rootValue) *
35// 100
36// ).toFixed(2) + `%`}`
37// })
38// const descriptiveStats = (array, label) => {
39// if (!array || array.length === 0) return
40// console.log(``)
41// console.log(label)
42// console.log(`count:`, array.length)
43// console.log(`min:`, ss.min(array))
44// console.log(`max:`, ss.max(array))
45// console.log(`mean:`, ss.mean(array))
46// console.log(`quantile 25:`, ss.quantile(array, 0.25))
47// console.log(`quantile 75:`, ss.quantile(array, 0.75))
48// }
49// process.on(`exit`, () => {
50// root.ROOT = convertHrtime(process.hrtime(root.ROOT)).milliseconds
51// root = labelify(root, root.ROOT)
52// for (var prop in root) {
53// if (_.isObject(root[prop]) && root[prop].ROOT) {
54// const rootValue = root[prop].ROOT
55// delete root[prop].ROOT
56// root[prop] = labelify(root[prop], rootValue)
57// }
58// }
59// console.log(``)
60// console.log(`===PROFILE===`)
61// console.log(treeify.asTree(root))
62// descriptiveStats(global.promiseMapTimes, `run-sift map nodes`)
63// })
64"use strict";
65//# sourceMappingURL=profile.js.map
\No newline at end of file