@fuzdev/fuz_util 0.42.0 → 0.43.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/LICENSE +1 -1
- package/README.md +19 -12
- package/dist/async.d.ts +2 -2
- package/dist/async.d.ts.map +1 -1
- package/dist/async.js +2 -2
- package/dist/benchmark.d.ts +179 -0
- package/dist/benchmark.d.ts.map +1 -0
- package/dist/benchmark.js +400 -0
- package/dist/benchmark_baseline.d.ts +195 -0
- package/dist/benchmark_baseline.d.ts.map +1 -0
- package/dist/benchmark_baseline.js +415 -0
- package/dist/benchmark_format.d.ts +92 -0
- package/dist/benchmark_format.d.ts.map +1 -0
- package/dist/benchmark_format.js +327 -0
- package/dist/benchmark_stats.d.ts +112 -0
- package/dist/benchmark_stats.d.ts.map +1 -0
- package/dist/benchmark_stats.js +336 -0
- package/dist/benchmark_types.d.ts +174 -0
- package/dist/benchmark_types.d.ts.map +1 -0
- package/dist/benchmark_types.js +1 -0
- package/dist/library_json.d.ts +3 -3
- package/dist/library_json.d.ts.map +1 -1
- package/dist/library_json.js +1 -1
- package/dist/object.js +1 -1
- package/dist/stats.d.ts +126 -0
- package/dist/stats.d.ts.map +1 -0
- package/dist/stats.js +262 -0
- package/dist/time.d.ts +161 -0
- package/dist/time.d.ts.map +1 -0
- package/dist/time.js +260 -0
- package/dist/timings.d.ts +1 -7
- package/dist/timings.d.ts.map +1 -1
- package/dist/timings.js +16 -16
- package/package.json +21 -19
- package/src/lib/async.ts +3 -3
- package/src/lib/benchmark.ts +498 -0
- package/src/lib/benchmark_baseline.ts +573 -0
- package/src/lib/benchmark_format.ts +379 -0
- package/src/lib/benchmark_stats.ts +448 -0
- package/src/lib/benchmark_types.ts +197 -0
- package/src/lib/library_json.ts +3 -3
- package/src/lib/object.ts +1 -1
- package/src/lib/stats.ts +353 -0
- package/src/lib/time.ts +314 -0
- package/src/lib/timings.ts +17 -17
- package/src/lib/types.ts +2 -2
package/src/lib/timings.ts
CHANGED
|
@@ -24,8 +24,8 @@ export type TimingsKey = string | number;
|
|
|
24
24
|
export class Timings {
|
|
25
25
|
readonly decimals: number | undefined;
|
|
26
26
|
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
readonly #timings: Map<TimingsKey, number | undefined> = new Map();
|
|
28
|
+
readonly #stopwatches: Map<TimingsKey, Stopwatch> = new Map();
|
|
29
29
|
|
|
30
30
|
constructor(decimals?: number) {
|
|
31
31
|
this.decimals = decimals;
|
|
@@ -35,41 +35,41 @@ export class Timings {
|
|
|
35
35
|
* Starts a timing operation for the given key.
|
|
36
36
|
*/
|
|
37
37
|
start(key: TimingsKey, decimals = this.decimals): () => number {
|
|
38
|
-
const final_key = this
|
|
39
|
-
this
|
|
40
|
-
this
|
|
41
|
-
return () => this
|
|
38
|
+
const final_key = this.#next_key(key);
|
|
39
|
+
this.#stopwatches.set(final_key, create_stopwatch(decimals));
|
|
40
|
+
this.#timings.set(final_key, undefined); // initializing to preserve order
|
|
41
|
+
return () => this.#stop(final_key);
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
-
|
|
45
|
-
if (!this
|
|
44
|
+
#next_key(key: TimingsKey): TimingsKey {
|
|
45
|
+
if (!this.#stopwatches.has(key)) return key;
|
|
46
46
|
let i = 2;
|
|
47
47
|
while (true) {
|
|
48
48
|
const next = key + '_' + i++;
|
|
49
|
-
if (!this
|
|
49
|
+
if (!this.#stopwatches.has(next)) return next;
|
|
50
50
|
}
|
|
51
51
|
}
|
|
52
52
|
|
|
53
53
|
/**
|
|
54
54
|
* Stops a timing operation and records the elapsed time.
|
|
55
55
|
*/
|
|
56
|
-
|
|
57
|
-
const stopwatch = this
|
|
56
|
+
#stop(key: TimingsKey): number {
|
|
57
|
+
const stopwatch = this.#stopwatches.get(key);
|
|
58
58
|
if (!stopwatch) return 0; // TODO maybe warn?
|
|
59
|
-
this
|
|
59
|
+
this.#stopwatches.delete(key);
|
|
60
60
|
const timing = stopwatch();
|
|
61
|
-
this
|
|
61
|
+
this.#timings.set(key, timing);
|
|
62
62
|
return timing;
|
|
63
63
|
}
|
|
64
64
|
|
|
65
65
|
get(key: TimingsKey): number {
|
|
66
|
-
const timing = this
|
|
66
|
+
const timing = this.#timings.get(key);
|
|
67
67
|
if (timing === undefined) return 0; // TODO maybe warn?
|
|
68
68
|
return timing;
|
|
69
69
|
}
|
|
70
70
|
|
|
71
71
|
entries(): IterableIterator<[TimingsKey, number | undefined]> {
|
|
72
|
-
return this
|
|
72
|
+
return this.#timings.entries();
|
|
73
73
|
}
|
|
74
74
|
|
|
75
75
|
/**
|
|
@@ -78,9 +78,9 @@ export class Timings {
|
|
|
78
78
|
*/
|
|
79
79
|
merge(timings: Timings): void {
|
|
80
80
|
for (const [key, timing] of timings.entries()) {
|
|
81
|
-
this
|
|
81
|
+
this.#timings.set(
|
|
82
82
|
key,
|
|
83
|
-
timing === undefined ? undefined : (this
|
|
83
|
+
timing === undefined ? undefined : (this.#timings.get(key) ?? 0) + timing,
|
|
84
84
|
);
|
|
85
85
|
}
|
|
86
86
|
}
|
package/src/lib/types.ts
CHANGED
|
@@ -21,9 +21,9 @@ export type OmitStrict<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;
|
|
|
21
21
|
* @see https://stackoverflow.com/users/5770132/oblosys
|
|
22
22
|
*/
|
|
23
23
|
export type PickUnion<T, K extends KeyofUnion<T>> = T extends unknown
|
|
24
|
-
? K & keyof T extends never
|
|
24
|
+
? K & keyof T extends never
|
|
25
25
|
? never
|
|
26
|
-
: Pick<T, K & keyof T>
|
|
26
|
+
: Pick<T, K & keyof T>
|
|
27
27
|
: never;
|
|
28
28
|
|
|
29
29
|
/**
|