@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.
Files changed (46) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +19 -12
  3. package/dist/async.d.ts +2 -2
  4. package/dist/async.d.ts.map +1 -1
  5. package/dist/async.js +2 -2
  6. package/dist/benchmark.d.ts +179 -0
  7. package/dist/benchmark.d.ts.map +1 -0
  8. package/dist/benchmark.js +400 -0
  9. package/dist/benchmark_baseline.d.ts +195 -0
  10. package/dist/benchmark_baseline.d.ts.map +1 -0
  11. package/dist/benchmark_baseline.js +415 -0
  12. package/dist/benchmark_format.d.ts +92 -0
  13. package/dist/benchmark_format.d.ts.map +1 -0
  14. package/dist/benchmark_format.js +327 -0
  15. package/dist/benchmark_stats.d.ts +112 -0
  16. package/dist/benchmark_stats.d.ts.map +1 -0
  17. package/dist/benchmark_stats.js +336 -0
  18. package/dist/benchmark_types.d.ts +174 -0
  19. package/dist/benchmark_types.d.ts.map +1 -0
  20. package/dist/benchmark_types.js +1 -0
  21. package/dist/library_json.d.ts +3 -3
  22. package/dist/library_json.d.ts.map +1 -1
  23. package/dist/library_json.js +1 -1
  24. package/dist/object.js +1 -1
  25. package/dist/stats.d.ts +126 -0
  26. package/dist/stats.d.ts.map +1 -0
  27. package/dist/stats.js +262 -0
  28. package/dist/time.d.ts +161 -0
  29. package/dist/time.d.ts.map +1 -0
  30. package/dist/time.js +260 -0
  31. package/dist/timings.d.ts +1 -7
  32. package/dist/timings.d.ts.map +1 -1
  33. package/dist/timings.js +16 -16
  34. package/package.json +21 -19
  35. package/src/lib/async.ts +3 -3
  36. package/src/lib/benchmark.ts +498 -0
  37. package/src/lib/benchmark_baseline.ts +573 -0
  38. package/src/lib/benchmark_format.ts +379 -0
  39. package/src/lib/benchmark_stats.ts +448 -0
  40. package/src/lib/benchmark_types.ts +197 -0
  41. package/src/lib/library_json.ts +3 -3
  42. package/src/lib/object.ts +1 -1
  43. package/src/lib/stats.ts +353 -0
  44. package/src/lib/time.ts +314 -0
  45. package/src/lib/timings.ts +17 -17
  46. package/src/lib/types.ts +2 -2
@@ -24,8 +24,8 @@ export type TimingsKey = string | number;
24
24
  export class Timings {
25
25
  readonly decimals: number | undefined;
26
26
 
27
- private readonly timings: Map<TimingsKey, number | undefined> = new Map();
28
- private readonly stopwatches: Map<TimingsKey, Stopwatch> = new Map();
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.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);
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
- private next_key(key: TimingsKey): TimingsKey {
45
- if (!this.stopwatches.has(key)) return key;
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.stopwatches.has(next)) return next;
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
- private stop(key: TimingsKey): number {
57
- const stopwatch = this.stopwatches.get(key);
56
+ #stop(key: TimingsKey): number {
57
+ const stopwatch = this.#stopwatches.get(key);
58
58
  if (!stopwatch) return 0; // TODO maybe warn?
59
- this.stopwatches.delete(key);
59
+ this.#stopwatches.delete(key);
60
60
  const timing = stopwatch();
61
- this.timings.set(key, timing);
61
+ this.#timings.set(key, timing);
62
62
  return timing;
63
63
  }
64
64
 
65
65
  get(key: TimingsKey): number {
66
- const timing = this.timings.get(key);
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.timings.entries();
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.timings.set(
81
+ this.#timings.set(
82
82
  key,
83
- timing === undefined ? undefined : (this.timings.get(key) ?? 0) + timing,
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 // eslint-disable-line @typescript-eslint/no-redundant-type-constituents
24
+ ? K & keyof T extends never
25
25
  ? never
26
- : Pick<T, K & keyof T> // eslint-disable-line @typescript-eslint/no-redundant-type-constituents
26
+ : Pick<T, K & keyof T>
27
27
  : never;
28
28
 
29
29
  /**