@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.d.cts CHANGED
@@ -1377,15 +1377,50 @@ interface ComparisonViewGroup {
1377
1377
  views: (ComparisonView | ComparisonUnresolvedView)[];
1378
1378
  }
1379
1379
 
1380
+ /**
1381
+ * A summary of timing samples collected during a performance run.
1382
+ */
1380
1383
  interface PerfReport {
1384
+ /** Minimum sample time, in milliseconds. */
1381
1385
  readonly minTime: number;
1386
+ /** Maximum sample time, in milliseconds. */
1382
1387
  readonly maxTime: number;
1388
+ /**
1389
+ * Trimmed mean (interquartile mean) computed from the middle 50% of samples,
1390
+ * in milliseconds. This is more robust against outliers than a simple mean.
1391
+ */
1383
1392
  readonly avgTime: number;
1393
+ /** Median (50th percentile) sample time, in milliseconds. */
1394
+ readonly medianTime: number;
1395
+ /** 95th percentile sample time, in milliseconds. */
1396
+ readonly p95Time: number;
1397
+ /** Population standard deviation across all samples, in milliseconds. */
1398
+ readonly stdDev: number;
1399
+ /** All recorded sample times, sorted ascending, in milliseconds. */
1384
1400
  readonly allTimes: number[];
1385
1401
  }
1402
+ /**
1403
+ * Collect performance timing samples and produce a robust statistical summary.
1404
+ */
1386
1405
  declare class PerfStats {
1387
1406
  private readonly times;
1407
+ /**
1408
+ * Record a single run time sample.
1409
+ *
1410
+ * @param timeInMillis The run time in milliseconds.
1411
+ */
1388
1412
  addRun(timeInMillis: number): void;
1413
+ /**
1414
+ * Get the raw run time samples that have been recorded.
1415
+ *
1416
+ * @returns A copy of the recorded run times, in insertion order.
1417
+ */
1418
+ getTimes(): number[];
1419
+ /**
1420
+ * Produce a `PerfReport` summarizing the recorded samples.
1421
+ *
1422
+ * @returns The summary report.
1423
+ */
1389
1424
  toReport(): PerfReport;
1390
1425
  }
1391
1426
 
package/dist/index.d.ts CHANGED
@@ -1377,15 +1377,50 @@ interface ComparisonViewGroup {
1377
1377
  views: (ComparisonView | ComparisonUnresolvedView)[];
1378
1378
  }
1379
1379
 
1380
+ /**
1381
+ * A summary of timing samples collected during a performance run.
1382
+ */
1380
1383
  interface PerfReport {
1384
+ /** Minimum sample time, in milliseconds. */
1381
1385
  readonly minTime: number;
1386
+ /** Maximum sample time, in milliseconds. */
1382
1387
  readonly maxTime: number;
1388
+ /**
1389
+ * Trimmed mean (interquartile mean) computed from the middle 50% of samples,
1390
+ * in milliseconds. This is more robust against outliers than a simple mean.
1391
+ */
1383
1392
  readonly avgTime: number;
1393
+ /** Median (50th percentile) sample time, in milliseconds. */
1394
+ readonly medianTime: number;
1395
+ /** 95th percentile sample time, in milliseconds. */
1396
+ readonly p95Time: number;
1397
+ /** Population standard deviation across all samples, in milliseconds. */
1398
+ readonly stdDev: number;
1399
+ /** All recorded sample times, sorted ascending, in milliseconds. */
1384
1400
  readonly allTimes: number[];
1385
1401
  }
1402
+ /**
1403
+ * Collect performance timing samples and produce a robust statistical summary.
1404
+ */
1386
1405
  declare class PerfStats {
1387
1406
  private readonly times;
1407
+ /**
1408
+ * Record a single run time sample.
1409
+ *
1410
+ * @param timeInMillis The run time in milliseconds.
1411
+ */
1388
1412
  addRun(timeInMillis: number): void;
1413
+ /**
1414
+ * Get the raw run time samples that have been recorded.
1415
+ *
1416
+ * @returns A copy of the recorded run times, in insertion order.
1417
+ */
1418
+ getTimes(): number[];
1419
+ /**
1420
+ * Produce a `PerfReport` summarizing the recorded samples.
1421
+ *
1422
+ * @returns The summary report.
1423
+ */
1389
1424
  toReport(): PerfReport;
1390
1425
  }
1391
1426
 
package/dist/index.js CHANGED
@@ -4576,34 +4576,76 @@ function handleRenames(origCurrentBundle, renamedDatasetKeys) {
4576
4576
  import { assertNever as assertNever11 } from "assert-never";
4577
4577
 
4578
4578
  // src/perf/perf-stats.ts
4579
+ function percentile(sorted, p) {
4580
+ if (sorted.length === 1) {
4581
+ return sorted[0];
4582
+ }
4583
+ const rank = p * (sorted.length - 1);
4584
+ const lo = Math.floor(rank);
4585
+ const hi = Math.ceil(rank);
4586
+ if (lo === hi) {
4587
+ return sorted[lo];
4588
+ }
4589
+ const frac = rank - lo;
4590
+ return sorted[lo] + (sorted[hi] - sorted[lo]) * frac;
4591
+ }
4579
4592
  var PerfStats = class {
4580
4593
  constructor() {
4581
4594
  this.times = [];
4582
4595
  }
4596
+ /**
4597
+ * Record a single run time sample.
4598
+ *
4599
+ * @param timeInMillis The run time in milliseconds.
4600
+ */
4583
4601
  addRun(timeInMillis) {
4584
4602
  this.times.push(timeInMillis);
4585
4603
  }
4604
+ /**
4605
+ * Get the raw run time samples that have been recorded.
4606
+ *
4607
+ * @returns A copy of the recorded run times, in insertion order.
4608
+ */
4609
+ getTimes() {
4610
+ return this.times.slice();
4611
+ }
4612
+ /**
4613
+ * Produce a `PerfReport` summarizing the recorded samples.
4614
+ *
4615
+ * @returns The summary report.
4616
+ */
4586
4617
  toReport() {
4587
4618
  if (this.times.length === 0) {
4588
4619
  return {
4589
4620
  minTime: 0,
4590
4621
  maxTime: 0,
4591
4622
  avgTime: 0,
4623
+ medianTime: 0,
4624
+ p95Time: 0,
4625
+ stdDev: 0,
4592
4626
  allTimes: []
4593
4627
  };
4594
4628
  }
4595
- const minTime = Math.min(...this.times);
4596
- const maxTime = Math.max(...this.times);
4597
- const sortedTimes = this.times.sort();
4598
- const minIndex = Math.floor(sortedTimes.length / 4);
4599
- const maxIndex = minIndex + Math.ceil(sortedTimes.length / 2);
4629
+ const sortedTimes = this.times.slice().sort((a, b) => a - b);
4630
+ const n = sortedTimes.length;
4631
+ const minTime = sortedTimes[0];
4632
+ const maxTime = sortedTimes[n - 1];
4633
+ const minIndex = Math.floor(n / 4);
4634
+ const maxIndex = minIndex + Math.max(1, Math.ceil(n / 2));
4600
4635
  const middleTimes = sortedTimes.slice(minIndex, maxIndex);
4601
- const totalTime = middleTimes.reduce((a, b) => a + b, 0);
4602
- const avgTime = totalTime / middleTimes.length;
4636
+ const avgTime = middleTimes.reduce((a, b) => a + b, 0) / middleTimes.length;
4637
+ const medianTime = percentile(sortedTimes, 0.5);
4638
+ const p95Time = percentile(sortedTimes, 0.95);
4639
+ const mean = sortedTimes.reduce((a, b) => a + b, 0) / n;
4640
+ const variance = sortedTimes.reduce((acc, t) => acc + (t - mean) * (t - mean), 0) / n;
4641
+ const stdDev = Math.sqrt(variance);
4603
4642
  return {
4604
4643
  minTime,
4605
4644
  maxTime,
4606
4645
  avgTime,
4646
+ medianTime,
4647
+ p95Time,
4648
+ stdDev,
4607
4649
  allTimes: sortedTimes
4608
4650
  };
4609
4651
  }