@sdeverywhere/check-core 0.1.10 → 0.1.11
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/dist/index.cjs +49 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +35 -0
- package/dist/index.d.ts +35 -0
- package/dist/index.js +49 -7
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -4631,34 +4631,76 @@ function handleRenames(origCurrentBundle, renamedDatasetKeys) {
|
|
|
4631
4631
|
var import_assert_never11 = require("assert-never");
|
|
4632
4632
|
|
|
4633
4633
|
// src/perf/perf-stats.ts
|
|
4634
|
+
function percentile(sorted, p) {
|
|
4635
|
+
if (sorted.length === 1) {
|
|
4636
|
+
return sorted[0];
|
|
4637
|
+
}
|
|
4638
|
+
const rank = p * (sorted.length - 1);
|
|
4639
|
+
const lo = Math.floor(rank);
|
|
4640
|
+
const hi = Math.ceil(rank);
|
|
4641
|
+
if (lo === hi) {
|
|
4642
|
+
return sorted[lo];
|
|
4643
|
+
}
|
|
4644
|
+
const frac = rank - lo;
|
|
4645
|
+
return sorted[lo] + (sorted[hi] - sorted[lo]) * frac;
|
|
4646
|
+
}
|
|
4634
4647
|
var PerfStats = class {
|
|
4635
4648
|
constructor() {
|
|
4636
4649
|
this.times = [];
|
|
4637
4650
|
}
|
|
4651
|
+
/**
|
|
4652
|
+
* Record a single run time sample.
|
|
4653
|
+
*
|
|
4654
|
+
* @param timeInMillis The run time in milliseconds.
|
|
4655
|
+
*/
|
|
4638
4656
|
addRun(timeInMillis) {
|
|
4639
4657
|
this.times.push(timeInMillis);
|
|
4640
4658
|
}
|
|
4659
|
+
/**
|
|
4660
|
+
* Get the raw run time samples that have been recorded.
|
|
4661
|
+
*
|
|
4662
|
+
* @returns A copy of the recorded run times, in insertion order.
|
|
4663
|
+
*/
|
|
4664
|
+
getTimes() {
|
|
4665
|
+
return this.times.slice();
|
|
4666
|
+
}
|
|
4667
|
+
/**
|
|
4668
|
+
* Produce a `PerfReport` summarizing the recorded samples.
|
|
4669
|
+
*
|
|
4670
|
+
* @returns The summary report.
|
|
4671
|
+
*/
|
|
4641
4672
|
toReport() {
|
|
4642
4673
|
if (this.times.length === 0) {
|
|
4643
4674
|
return {
|
|
4644
4675
|
minTime: 0,
|
|
4645
4676
|
maxTime: 0,
|
|
4646
4677
|
avgTime: 0,
|
|
4678
|
+
medianTime: 0,
|
|
4679
|
+
p95Time: 0,
|
|
4680
|
+
stdDev: 0,
|
|
4647
4681
|
allTimes: []
|
|
4648
4682
|
};
|
|
4649
4683
|
}
|
|
4650
|
-
const
|
|
4651
|
-
const
|
|
4652
|
-
const
|
|
4653
|
-
const
|
|
4654
|
-
const
|
|
4684
|
+
const sortedTimes = this.times.slice().sort((a, b) => a - b);
|
|
4685
|
+
const n = sortedTimes.length;
|
|
4686
|
+
const minTime = sortedTimes[0];
|
|
4687
|
+
const maxTime = sortedTimes[n - 1];
|
|
4688
|
+
const minIndex = Math.floor(n / 4);
|
|
4689
|
+
const maxIndex = minIndex + Math.max(1, Math.ceil(n / 2));
|
|
4655
4690
|
const middleTimes = sortedTimes.slice(minIndex, maxIndex);
|
|
4656
|
-
const
|
|
4657
|
-
const
|
|
4691
|
+
const avgTime = middleTimes.reduce((a, b) => a + b, 0) / middleTimes.length;
|
|
4692
|
+
const medianTime = percentile(sortedTimes, 0.5);
|
|
4693
|
+
const p95Time = percentile(sortedTimes, 0.95);
|
|
4694
|
+
const mean = sortedTimes.reduce((a, b) => a + b, 0) / n;
|
|
4695
|
+
const variance = sortedTimes.reduce((acc, t) => acc + (t - mean) * (t - mean), 0) / n;
|
|
4696
|
+
const stdDev = Math.sqrt(variance);
|
|
4658
4697
|
return {
|
|
4659
4698
|
minTime,
|
|
4660
4699
|
maxTime,
|
|
4661
4700
|
avgTime,
|
|
4701
|
+
medianTime,
|
|
4702
|
+
p95Time,
|
|
4703
|
+
stdDev,
|
|
4662
4704
|
allTimes: sortedTimes
|
|
4663
4705
|
};
|
|
4664
4706
|
}
|