@xylabs/profile 5.0.83 → 5.0.84
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/README.md +16 -0
- package/dist/neutral/index.mjs.map +1 -1
- package/dist/neutral/profiler.d.ts +12 -0
- package/dist/neutral/profiler.d.ts.map +1 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -43,6 +43,8 @@ Base functionality used throughout XY Labs TypeScript/JavaScript libraries
|
|
|
43
43
|
function createProfiler(): Profiler;
|
|
44
44
|
```
|
|
45
45
|
|
|
46
|
+
Creates a new empty profiler instance.
|
|
47
|
+
|
|
46
48
|
## Returns
|
|
47
49
|
|
|
48
50
|
[`Profiler`](#../type-aliases/Profiler)
|
|
@@ -57,16 +59,22 @@ function createProfiler(): Profiler;
|
|
|
57
59
|
function profile(profiler, name): void;
|
|
58
60
|
```
|
|
59
61
|
|
|
62
|
+
Records a timestamp for the given profile name.
|
|
63
|
+
|
|
60
64
|
## Parameters
|
|
61
65
|
|
|
62
66
|
### profiler
|
|
63
67
|
|
|
64
68
|
[`Profiler`](#../type-aliases/Profiler)
|
|
65
69
|
|
|
70
|
+
The profiler instance to record into.
|
|
71
|
+
|
|
66
72
|
### name
|
|
67
73
|
|
|
68
74
|
`string`
|
|
69
75
|
|
|
76
|
+
The name of the timing entry.
|
|
77
|
+
|
|
70
78
|
## Returns
|
|
71
79
|
|
|
72
80
|
`void`
|
|
@@ -81,16 +89,22 @@ function profile(profiler, name): void;
|
|
|
81
89
|
function profileReport(profiler): Record<string, number>;
|
|
82
90
|
```
|
|
83
91
|
|
|
92
|
+
Generates a report of elapsed times for each profiled entry.
|
|
93
|
+
|
|
84
94
|
## Parameters
|
|
85
95
|
|
|
86
96
|
### profiler
|
|
87
97
|
|
|
88
98
|
[`Profiler`](#../type-aliases/Profiler)
|
|
89
99
|
|
|
100
|
+
The profiler instance to report on.
|
|
101
|
+
|
|
90
102
|
## Returns
|
|
91
103
|
|
|
92
104
|
`Record`\<`string`, `number`\>
|
|
93
105
|
|
|
106
|
+
A record mapping each profile name to its elapsed time in milliseconds, plus a '-all-' total.
|
|
107
|
+
|
|
94
108
|
### type-aliases
|
|
95
109
|
|
|
96
110
|
### <a id="Profiler"></a>Profiler
|
|
@@ -103,6 +117,8 @@ function profileReport(profiler): Record<string, number>;
|
|
|
103
117
|
type Profiler = Record<string, number[]>;
|
|
104
118
|
```
|
|
105
119
|
|
|
120
|
+
A record of named timing entries, where each key maps to an array of timestamps.
|
|
121
|
+
|
|
106
122
|
|
|
107
123
|
Part of [sdk-js](https://www.npmjs.com/package/@xyo-network/sdk-js)
|
|
108
124
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/profiler.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"sources":["../../src/profiler.ts"],"sourcesContent":["/** A record of named timing entries, where each key maps to an array of timestamps. */\nexport type Profiler = Record<string, number[]>\n\n/** Creates a new empty profiler instance. */\nexport const createProfiler = (): Profiler => {\n return {}\n}\n\n/**\n * Records a timestamp for the given profile name.\n * @param profiler - The profiler instance to record into.\n * @param name - The name of the timing entry.\n */\nexport const profile = (profiler: Profiler, name: string) => {\n const timeData = profiler[name] ?? []\n timeData.push(Date.now())\n profiler[name] = timeData\n}\n\n/**\n * Generates a report of elapsed times for each profiled entry.\n * @param profiler - The profiler instance to report on.\n * @returns A record mapping each profile name to its elapsed time in milliseconds, plus a '-all-' total.\n */\nexport const profileReport = (profiler: Profiler) => {\n let lowest = Date.now()\n let highest = 0\n // eslint-disable-next-line unicorn/no-array-reduce\n const results = Object.entries(profiler).reduce<Record<string, number>>((prev, [name, readings]) => {\n const start = readings.at(0)\n if (start !== undefined) {\n if (start < lowest) {\n lowest = start\n }\n const end = readings.at(-1) ?? Date.now()\n if (end > highest) {\n highest = end\n }\n prev[name] = end - start\n }\n return prev\n }, {})\n if (highest > 0) {\n results['-all-'] = highest - lowest\n }\n return results\n}\n"],"mappings":";AAIO,IAAM,iBAAiB,MAAgB;AAC5C,SAAO,CAAC;AACV;AAOO,IAAM,UAAU,CAAC,UAAoB,SAAiB;AAC3D,QAAM,WAAW,SAAS,IAAI,KAAK,CAAC;AACpC,WAAS,KAAK,KAAK,IAAI,CAAC;AACxB,WAAS,IAAI,IAAI;AACnB;AAOO,IAAM,gBAAgB,CAAC,aAAuB;AACnD,MAAI,SAAS,KAAK,IAAI;AACtB,MAAI,UAAU;AAEd,QAAM,UAAU,OAAO,QAAQ,QAAQ,EAAE,OAA+B,CAAC,MAAM,CAAC,MAAM,QAAQ,MAAM;AAClG,UAAM,QAAQ,SAAS,GAAG,CAAC;AAC3B,QAAI,UAAU,QAAW;AACvB,UAAI,QAAQ,QAAQ;AAClB,iBAAS;AAAA,MACX;AACA,YAAM,MAAM,SAAS,GAAG,EAAE,KAAK,KAAK,IAAI;AACxC,UAAI,MAAM,SAAS;AACjB,kBAAU;AAAA,MACZ;AACA,WAAK,IAAI,IAAI,MAAM;AAAA,IACrB;AACA,WAAO;AAAA,EACT,GAAG,CAAC,CAAC;AACL,MAAI,UAAU,GAAG;AACf,YAAQ,OAAO,IAAI,UAAU;AAAA,EAC/B;AACA,SAAO;AACT;","names":[]}
|
|
@@ -1,5 +1,17 @@
|
|
|
1
|
+
/** A record of named timing entries, where each key maps to an array of timestamps. */
|
|
1
2
|
export type Profiler = Record<string, number[]>;
|
|
3
|
+
/** Creates a new empty profiler instance. */
|
|
2
4
|
export declare const createProfiler: () => Profiler;
|
|
5
|
+
/**
|
|
6
|
+
* Records a timestamp for the given profile name.
|
|
7
|
+
* @param profiler - The profiler instance to record into.
|
|
8
|
+
* @param name - The name of the timing entry.
|
|
9
|
+
*/
|
|
3
10
|
export declare const profile: (profiler: Profiler, name: string) => void;
|
|
11
|
+
/**
|
|
12
|
+
* Generates a report of elapsed times for each profiled entry.
|
|
13
|
+
* @param profiler - The profiler instance to report on.
|
|
14
|
+
* @returns A record mapping each profile name to its elapsed time in milliseconds, plus a '-all-' total.
|
|
15
|
+
*/
|
|
4
16
|
export declare const profileReport: (profiler: Profiler) => Record<string, number>;
|
|
5
17
|
//# sourceMappingURL=profiler.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"profiler.d.ts","sourceRoot":"","sources":["../../src/profiler.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAA;AAE/C,eAAO,MAAM,cAAc,QAAO,QAEjC,CAAA;AAED,eAAO,MAAM,OAAO,GAAI,UAAU,QAAQ,EAAE,MAAM,MAAM,SAIvD,CAAA;AAED,eAAO,MAAM,aAAa,GAAI,UAAU,QAAQ,2BAsB/C,CAAA"}
|
|
1
|
+
{"version":3,"file":"profiler.d.ts","sourceRoot":"","sources":["../../src/profiler.ts"],"names":[],"mappings":"AAAA,uFAAuF;AACvF,MAAM,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAA;AAE/C,6CAA6C;AAC7C,eAAO,MAAM,cAAc,QAAO,QAEjC,CAAA;AAED;;;;GAIG;AACH,eAAO,MAAM,OAAO,GAAI,UAAU,QAAQ,EAAE,MAAM,MAAM,SAIvD,CAAA;AAED;;;;GAIG;AACH,eAAO,MAAM,aAAa,GAAI,UAAU,QAAQ,2BAsB/C,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xylabs/profile",
|
|
3
|
-
"version": "5.0.
|
|
3
|
+
"version": "5.0.84",
|
|
4
4
|
"description": "Base functionality used throughout XY Labs TypeScript/JavaScript libraries",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"profile",
|
|
@@ -43,8 +43,8 @@
|
|
|
43
43
|
"!**/*.test.*"
|
|
44
44
|
],
|
|
45
45
|
"devDependencies": {
|
|
46
|
-
"@xylabs/ts-scripts-yarn3": "~7.4.
|
|
47
|
-
"@xylabs/tsconfig": "~7.4.
|
|
46
|
+
"@xylabs/ts-scripts-yarn3": "~7.4.13",
|
|
47
|
+
"@xylabs/tsconfig": "~7.4.13",
|
|
48
48
|
"typescript": "~5.9.3",
|
|
49
49
|
"vitest": "^4.0.18"
|
|
50
50
|
},
|