@universal-packages/time-measurer 1.5.0 → 2.0.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/Benchmark.d.ts +24 -0
- package/Benchmark.d.ts.map +1 -0
- package/Benchmark.js +82 -0
- package/Benchmark.js.map +1 -0
- package/Benchmark.types.d.ts +28 -0
- package/Benchmark.types.d.ts.map +1 -0
- package/Benchmark.types.js +2 -0
- package/Benchmark.types.js.map +1 -0
- package/Measurement.d.ts +45 -3
- package/Measurement.d.ts.map +1 -0
- package/Measurement.js +48 -6
- package/Measurement.js.map +1 -1
- package/Measurement.types.d.ts +1 -0
- package/Measurement.types.d.ts.map +1 -0
- package/Measurement.types.js +1 -2
- package/README.md +413 -55
- package/Sleep.d.ts +5 -0
- package/Sleep.d.ts.map +1 -0
- package/Sleep.js +8 -0
- package/Sleep.js.map +1 -0
- package/TimeMeasurer.d.ts +15 -10
- package/TimeMeasurer.d.ts.map +1 -0
- package/TimeMeasurer.js +23 -20
- package/TimeMeasurer.js.map +1 -1
- package/TimeProfiler.d.ts +71 -0
- package/TimeProfiler.d.ts.map +1 -0
- package/TimeProfiler.js +171 -0
- package/TimeProfiler.js.map +1 -0
- package/TimeProfiler.types.d.ts +20 -0
- package/TimeProfiler.types.d.ts.map +1 -0
- package/TimeProfiler.types.js +2 -0
- package/TimeProfiler.types.js.map +1 -0
- package/index.d.ts +8 -4
- package/index.d.ts.map +1 -0
- package/index.js +8 -28
- package/index.js.map +1 -1
- package/package.json +22 -23
- package/sleep.d.ts +0 -2
- package/sleep.js +0 -8
- package/sleep.js.map +0 -1
- package/startMeasurement.d.ts +0 -2
- package/startMeasurement.js +0 -14
- package/startMeasurement.js.map +0 -1
package/Benchmark.d.ts
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
import { BenchmarkOptions, BenchmarkResult } from './Benchmark.types';
|
2
|
+
export declare class Benchmark {
|
3
|
+
private options;
|
4
|
+
constructor(options?: BenchmarkOptions);
|
5
|
+
/**
|
6
|
+
* Run the benchmark with the provided function
|
7
|
+
* @param fn - The function to benchmark
|
8
|
+
* @returns BenchmarkResult containing all measurements and statistics
|
9
|
+
*/
|
10
|
+
run(fn: () => void): BenchmarkResult;
|
11
|
+
/**
|
12
|
+
* Run an async function benchmark
|
13
|
+
* @param fn - The async function to benchmark
|
14
|
+
* @returns Promise<BenchmarkResult> containing all measurements and statistics
|
15
|
+
*/
|
16
|
+
runAsync(fn: () => Promise<void>): Promise<BenchmarkResult>;
|
17
|
+
/**
|
18
|
+
* Calculate statistics from measurements
|
19
|
+
* @param measurements - Array of measurements
|
20
|
+
* @returns BenchmarkResult with calculated statistics
|
21
|
+
*/
|
22
|
+
private calculateStatistics;
|
23
|
+
}
|
24
|
+
//# sourceMappingURL=Benchmark.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"Benchmark.d.ts","sourceRoot":"","sources":["../src/Benchmark.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AAIrE,qBAAa,SAAS;IACpB,OAAO,CAAC,OAAO,CAA4B;gBAE/B,OAAO,CAAC,EAAE,gBAAgB;IAStC;;;;OAIG;IACI,GAAG,CAAC,EAAE,EAAE,MAAM,IAAI,GAAG,eAAe;IAqB3C;;;;OAIG;IACU,QAAQ,CAAC,EAAE,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,eAAe,CAAC;IAqBxE;;;;OAIG;IACH,OAAO,CAAC,mBAAmB;CA0B5B"}
|
package/Benchmark.js
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
import { Measurement } from './Measurement';
|
2
|
+
import { TimeMeasurer } from './TimeMeasurer';
|
3
|
+
export class Benchmark {
|
4
|
+
options;
|
5
|
+
constructor(options) {
|
6
|
+
this.options = {
|
7
|
+
iterations: 1,
|
8
|
+
warmupIterations: 0,
|
9
|
+
name: 'Unnamed Benchmark',
|
10
|
+
...options
|
11
|
+
};
|
12
|
+
}
|
13
|
+
/**
|
14
|
+
* Run the benchmark with the provided function
|
15
|
+
* @param fn - The function to benchmark
|
16
|
+
* @returns BenchmarkResult containing all measurements and statistics
|
17
|
+
*/
|
18
|
+
run(fn) {
|
19
|
+
const measurements = [];
|
20
|
+
// Perform warmup iterations
|
21
|
+
for (let i = 0; i < this.options.warmupIterations; i++) {
|
22
|
+
fn();
|
23
|
+
}
|
24
|
+
// Perform actual benchmark iterations
|
25
|
+
for (let i = 0; i < this.options.iterations; i++) {
|
26
|
+
const measurer = TimeMeasurer.start();
|
27
|
+
fn();
|
28
|
+
const measurement = measurer.finish();
|
29
|
+
measurements.push(measurement);
|
30
|
+
}
|
31
|
+
const result = this.calculateStatistics(measurements);
|
32
|
+
return result;
|
33
|
+
}
|
34
|
+
/**
|
35
|
+
* Run an async function benchmark
|
36
|
+
* @param fn - The async function to benchmark
|
37
|
+
* @returns Promise<BenchmarkResult> containing all measurements and statistics
|
38
|
+
*/
|
39
|
+
async runAsync(fn) {
|
40
|
+
const measurements = [];
|
41
|
+
// Perform warmup iterations
|
42
|
+
for (let i = 0; i < this.options.warmupIterations; i++) {
|
43
|
+
await fn();
|
44
|
+
}
|
45
|
+
// Perform actual benchmark iterations
|
46
|
+
for (let i = 0; i < this.options.iterations; i++) {
|
47
|
+
const measurer = TimeMeasurer.start();
|
48
|
+
await fn();
|
49
|
+
const measurement = measurer.finish();
|
50
|
+
measurements.push(measurement);
|
51
|
+
}
|
52
|
+
const result = this.calculateStatistics(measurements);
|
53
|
+
return result;
|
54
|
+
}
|
55
|
+
/**
|
56
|
+
* Calculate statistics from measurements
|
57
|
+
* @param measurements - Array of measurements
|
58
|
+
* @returns BenchmarkResult with calculated statistics
|
59
|
+
*/
|
60
|
+
calculateStatistics(measurements) {
|
61
|
+
if (measurements.length === 0) {
|
62
|
+
throw new Error('No measurements to calculate statistics from');
|
63
|
+
}
|
64
|
+
// Convert measurements to nanoseconds for calculations
|
65
|
+
const nanoseconds = measurements.map((m) => BigInt(m.hours) * 3600000000000n + BigInt(m.minutes) * 60000000000n + BigInt(m.seconds) * 1000000000n + BigInt(Math.round(m.milliseconds * 1000000)));
|
66
|
+
const minNs = nanoseconds.reduce((min, current) => (current < min ? current : min));
|
67
|
+
const maxNs = nanoseconds.reduce((max, current) => (current > max ? current : max));
|
68
|
+
const totalNs = nanoseconds.reduce((sum, current) => sum + current, 0n);
|
69
|
+
const averageNs = totalNs / BigInt(nanoseconds.length);
|
70
|
+
return {
|
71
|
+
name: this.options.name,
|
72
|
+
iterations: this.options.iterations,
|
73
|
+
warmupIterations: this.options.warmupIterations,
|
74
|
+
measurements,
|
75
|
+
min: new Measurement(minNs),
|
76
|
+
max: new Measurement(maxNs),
|
77
|
+
average: new Measurement(averageNs),
|
78
|
+
total: new Measurement(totalNs)
|
79
|
+
};
|
80
|
+
}
|
81
|
+
}
|
82
|
+
//# sourceMappingURL=Benchmark.js.map
|
package/Benchmark.js.map
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"Benchmark.js","sourceRoot":"","sources":["../src/Benchmark.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAC3C,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAE7C,MAAM,OAAO,SAAS;IACZ,OAAO,CAA4B;IAE3C,YAAY,OAA0B;QACpC,IAAI,CAAC,OAAO,GAAG;YACb,UAAU,EAAE,CAAC;YACb,gBAAgB,EAAE,CAAC;YACnB,IAAI,EAAE,mBAAmB;YACzB,GAAG,OAAO;SACX,CAAA;IACH,CAAC;IAED;;;;OAIG;IACI,GAAG,CAAC,EAAc;QACvB,MAAM,YAAY,GAAkB,EAAE,CAAA;QAEtC,4BAA4B;QAC5B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,OAAO,CAAC,gBAAgB,EAAE,CAAC,EAAE,EAAE,C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GAAG,EAAE,IAAI,WAAW,CAAC,KAAK,CAAC;YAC3B,OAAO,EAAE,IAAI,WAAW,CAAC,SAAS,CAAC;YACnC,KAAK,EAAE,IAAI,WAAW,CAAC,OAAO,CAAC;SAChC,CAAA;IACH,CAAC;CACF"}
|
@@ -0,0 +1,28 @@
|
|
1
|
+
import { Measurement } from './Measurement';
|
2
|
+
export interface BenchmarkOptions {
|
3
|
+
/** Number of iterations to run the benchmark */
|
4
|
+
iterations?: number;
|
5
|
+
/** Number of warmup iterations before actual measurement */
|
6
|
+
warmupIterations?: number;
|
7
|
+
/** Name/description of the benchmark */
|
8
|
+
name?: string;
|
9
|
+
}
|
10
|
+
export interface BenchmarkResult {
|
11
|
+
/** Name of the benchmark */
|
12
|
+
name: string;
|
13
|
+
/** Total number of iterations performed */
|
14
|
+
iterations: number;
|
15
|
+
/** Number of warmup iterations performed */
|
16
|
+
warmupIterations: number;
|
17
|
+
/** All individual measurements */
|
18
|
+
measurements: Measurement[];
|
19
|
+
/** Minimum measurement */
|
20
|
+
min: Measurement;
|
21
|
+
/** Maximum measurement */
|
22
|
+
max: Measurement;
|
23
|
+
/** Average measurement */
|
24
|
+
average: Measurement;
|
25
|
+
/** Total time for all iterations */
|
26
|
+
total: Measurement;
|
27
|
+
}
|
28
|
+
//# sourceMappingURL=Benchmark.types.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"Benchmark.types.d.ts","sourceRoot":"","sources":["../src/Benchmark.types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAE3C,MAAM,WAAW,gBAAgB;IAC/B,gDAAgD;IAChD,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,4DAA4D;IAC5D,gBAAgB,CAAC,EAAE,MAAM,CAAA;IACzB,wCAAwC;IACxC,IAAI,CAAC,EAAE,MAAM,CAAA;CACd;AAED,MAAM,WAAW,eAAe;IAC9B,4BAA4B;IAC5B,IAAI,EAAE,MAAM,CAAA;IACZ,2CAA2C;IAC3C,UAAU,EAAE,MAAM,CAAA;IAClB,4CAA4C;IAC5C,gBAAgB,EAAE,MAAM,CAAA;IACxB,kCAAkC;IAClC,YAAY,EAAE,WAAW,EAAE,CAAA;IAC3B,0BAA0B;IAC1B,GAAG,EAAE,WAAW,CAAA;IAChB,0BAA0B;IAC1B,GAAG,EAAE,WAAW,CAAA;IAChB,0BAA0B;IAC1B,OAAO,EAAE,WAAW,CAAA;IACpB,oCAAoC;IACpC,KAAK,EAAE,WAAW,CAAA;CACnB"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"Benchmark.types.js","sourceRoot":"","sources":["../src/Benchmark.types.ts"],"names":[],"mappings":""}
|
package/Measurement.d.ts
CHANGED
@@ -1,16 +1,58 @@
|
|
1
1
|
import { TimeFormat } from './Measurement.types';
|
2
|
-
export
|
2
|
+
export declare class Measurement {
|
3
3
|
readonly hours: number;
|
4
4
|
readonly minutes: number;
|
5
5
|
readonly seconds: number;
|
6
6
|
readonly milliseconds: number;
|
7
7
|
constructor(nanoseconds: bigint);
|
8
|
-
/**
|
8
|
+
/**
|
9
|
+
* Convert the measurement to a string
|
10
|
+
* @param format - The format to convert the measurement to
|
11
|
+
* @returns The measurement as a string
|
12
|
+
*/
|
9
13
|
toString(format?: TimeFormat): string;
|
10
|
-
/**
|
14
|
+
/**
|
15
|
+
* Convert the measurement to a date
|
16
|
+
* @returns The measurement as a date
|
17
|
+
*/
|
11
18
|
toDate(): Date;
|
19
|
+
/**
|
20
|
+
* Convert the measurement to a condensed string
|
21
|
+
*
|
22
|
+
* 1000ms = 1.000s
|
23
|
+
* 60s = 1m
|
24
|
+
* 60m = 1h
|
25
|
+
*
|
26
|
+
* @returns The measurement as a condensed string
|
27
|
+
*/
|
12
28
|
private getCondensed;
|
29
|
+
/**
|
30
|
+
* Convert the measurement to a human readable string
|
31
|
+
*
|
32
|
+
* 1000ms = 1.000sec
|
33
|
+
* 60s = 1min
|
34
|
+
* 60m = 1hrs
|
35
|
+
*
|
36
|
+
* @returns The measurement as a human readable string
|
37
|
+
*/
|
13
38
|
private getHuman;
|
39
|
+
/**
|
40
|
+
* Convert the measurement to a expressive string
|
41
|
+
*
|
42
|
+
* 1000ms = 1.000 Second
|
43
|
+
* 60s = 1 Minute
|
44
|
+
* 60m = 1 Hour
|
45
|
+
*
|
46
|
+
* @returns The measurement as a expressive string
|
47
|
+
*/
|
14
48
|
private gerExpressive;
|
49
|
+
/**
|
50
|
+
* Pad a number with zeros
|
51
|
+
* @param num - The number to pad
|
52
|
+
* @param places - The number of places to pad the number to
|
53
|
+
* @param fixPositions - The number of positions to fix the number to
|
54
|
+
* @returns The padded number
|
55
|
+
*/
|
15
56
|
private pad;
|
16
57
|
}
|
58
|
+
//# sourceMappingURL=Measurement.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"Measurement.d.ts","sourceRoot":"","sources":["../src/Measurement.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAA;AAEhD,qBAAa,WAAW;IACtB,SAAgB,KAAK,EAAE,MAAM,CAAA;IAC7B,SAAgB,OAAO,EAAE,MAAM,CAAA;IAC/B,SAAgB,OAAO,EAAE,MAAM,CAAA;IAC/B,SAAgB,YAAY,EAAE,MAAM,CAAA;gBAEjB,WAAW,EAAE,MAAM;IAetC;;;;OAIG;IACI,QAAQ,CAAC,MAAM,GAAE,UAAoB,GAAG,MAAM;IAWrD;;;OAGG;IACI,MAAM,IAAI,IAAI;IAIrB;;;;;;;;OAQG;IACH,OAAO,CAAC,YAAY;IAYpB;;;;;;;;OAQG;IACH,OAAO,CAAC,QAAQ;IAYhB;;;;;;;;OAQG;IACH,OAAO,CAAC,aAAa;IAYrB;;;;;;OAMG;IACH,OAAO,CAAC,GAAG;CAGZ"}
|
package/Measurement.js
CHANGED
@@ -1,6 +1,8 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
1
|
+
export class Measurement {
|
2
|
+
hours;
|
3
|
+
minutes;
|
4
|
+
seconds;
|
5
|
+
milliseconds;
|
4
6
|
constructor(nanoseconds) {
|
5
7
|
let currentNanoseconds = nanoseconds;
|
6
8
|
this.hours = Number(currentNanoseconds / 3600000000000n);
|
@@ -11,7 +13,11 @@ class Measurement {
|
|
11
13
|
currentNanoseconds = currentNanoseconds - BigInt(Math.floor(this.seconds)) * 1000000000n;
|
12
14
|
this.milliseconds = Number(currentNanoseconds) / 1000000;
|
13
15
|
}
|
14
|
-
/**
|
16
|
+
/**
|
17
|
+
* Convert the measurement to a string
|
18
|
+
* @param format - The format to convert the measurement to
|
19
|
+
* @returns The measurement as a string
|
20
|
+
*/
|
15
21
|
toString(format = 'Human') {
|
16
22
|
switch (format) {
|
17
23
|
case 'Condensed':
|
@@ -22,10 +28,22 @@ class Measurement {
|
|
22
28
|
return this.gerExpressive();
|
23
29
|
}
|
24
30
|
}
|
25
|
-
/**
|
31
|
+
/**
|
32
|
+
* Convert the measurement to a date
|
33
|
+
* @returns The measurement as a date
|
34
|
+
*/
|
26
35
|
toDate() {
|
27
36
|
return new Date(0, 0, 0, this.hours, this.minutes, this.seconds, this.milliseconds);
|
28
37
|
}
|
38
|
+
/**
|
39
|
+
* Convert the measurement to a condensed string
|
40
|
+
*
|
41
|
+
* 1000ms = 1.000s
|
42
|
+
* 60s = 1m
|
43
|
+
* 60m = 1h
|
44
|
+
*
|
45
|
+
* @returns The measurement as a condensed string
|
46
|
+
*/
|
29
47
|
getCondensed() {
|
30
48
|
if (this.hours !== 0) {
|
31
49
|
return `${this.pad(this.hours)}:${this.pad(this.minutes)}:${this.pad(this.seconds)}.${this.pad(this.milliseconds, 3)}`;
|
@@ -40,6 +58,15 @@ class Measurement {
|
|
40
58
|
return `${this.pad(this.milliseconds, 3, 2)}`;
|
41
59
|
}
|
42
60
|
}
|
61
|
+
/**
|
62
|
+
* Convert the measurement to a human readable string
|
63
|
+
*
|
64
|
+
* 1000ms = 1.000sec
|
65
|
+
* 60s = 1min
|
66
|
+
* 60m = 1hrs
|
67
|
+
*
|
68
|
+
* @returns The measurement as a human readable string
|
69
|
+
*/
|
43
70
|
getHuman() {
|
44
71
|
if (this.hours !== 0) {
|
45
72
|
return `${this.hours}hrs ${this.minutes}min ${this.seconds}.${this.pad(this.milliseconds, 3)}sec`;
|
@@ -54,6 +81,15 @@ class Measurement {
|
|
54
81
|
return `${this.pad(this.milliseconds, 3, 2)}ms`;
|
55
82
|
}
|
56
83
|
}
|
84
|
+
/**
|
85
|
+
* Convert the measurement to a expressive string
|
86
|
+
*
|
87
|
+
* 1000ms = 1.000 Second
|
88
|
+
* 60s = 1 Minute
|
89
|
+
* 60m = 1 Hour
|
90
|
+
*
|
91
|
+
* @returns The measurement as a expressive string
|
92
|
+
*/
|
57
93
|
gerExpressive() {
|
58
94
|
if (this.hours !== 0) {
|
59
95
|
return `${this.hours} Hours, ${this.minutes} Minutes, and ${this.seconds}.${this.pad(this.milliseconds, 3)} Seconds`;
|
@@ -68,9 +104,15 @@ class Measurement {
|
|
68
104
|
return `${this.pad(this.milliseconds, 3, 2)} Milliseconds`;
|
69
105
|
}
|
70
106
|
}
|
107
|
+
/**
|
108
|
+
* Pad a number with zeros
|
109
|
+
* @param num - The number to pad
|
110
|
+
* @param places - The number of places to pad the number to
|
111
|
+
* @param fixPositions - The number of positions to fix the number to
|
112
|
+
* @returns The padded number
|
113
|
+
*/
|
71
114
|
pad(num, places = 2, fixPositions = 0) {
|
72
115
|
return num.toFixed(fixPositions).padStart(places, '0');
|
73
116
|
}
|
74
117
|
}
|
75
|
-
exports.default = Measurement;
|
76
118
|
//# sourceMappingURL=Measurement.js.map
|
package/Measurement.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"Measurement.js","sourceRoot":"","sources":["../src/Measurement.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"Measurement.js","sourceRoot":"","sources":["../src/Measurement.ts"],"names":[],"mappings":"AAEA,MAA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O,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,YAAY,EAAE,CAAC,EAAE,CAAC,CAAC,eAAe,CAAA;QAC5D,CAAC;IACH,CAAC;IAED;;;;;;OAMG;IACK,GAAG,CAAC,GAAW,EAAE,MAAM,GAAG,CAAC,EAAE,YAAY,GAAG,CAAC;QACnD,OAAO,GAAG,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC,QAAQ,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;IACxD,CAAC;CACF"}
|
package/Measurement.types.d.ts
CHANGED
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"Measurement.types.d.ts","sourceRoot":"","sources":["../src/Measurement.types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,UAAU,GAAG,YAAY,GAAG,OAAO,GAAG,WAAW,CAAA"}
|
package/Measurement.types.js
CHANGED