@nestia/benchmark 14.0.1 → 14.0.2

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.
@@ -0,0 +1,25 @@
1
+ import type { DynamicBenchmarker } from "../DynamicBenchmarker";
2
+ import type { IBenchmarkEvent } from "../IBenchmarkEvent";
3
+ /**
4
+ * Statistics of benchmarked events.
5
+ *
6
+ * @evidence contracts/common.md#principled-implementation The success count uses one reduction without retaining a filtered event array, while mean, population standard deviation, minimum and maximum share one pass over event start/completion durations. Both operations are linear in the event population.
7
+ * @evidence contracts/common.md#clear-and-simple-design One namespace with one exported function; the elapsed-time measures are a private helper of it.
8
+ * @evidence contracts/common.md#prohibited-implementation-shortcuts The formulas are standard statistics without tuning to any benchmark result.
9
+ * @evidence contracts/common.md#meaningful-documentation The comment states its single job.
10
+ */
11
+ export declare namespace DynamicBenchmarkStatistics {
12
+ /**
13
+ * Summarizes events into counts and elapsed-time statistics.
14
+ *
15
+ * Durations are milliseconds. The empty set has `null` measures, and the
16
+ * standard deviation is the population deviation computed with Welford's
17
+ * update.
18
+ *
19
+ * @evidence contracts/common.md#principled-implementation Welford's update accumulates deviations from a running mean, avoiding the subtraction of nearly equal large squared averages that caused cancellation in constant durations. The variance divisor is the population count; floating-point arithmetic remains approximate rather than a claim of exact arithmetic for every possible input.
20
+ * @evidence contracts/common.md#clear-and-simple-design One shared pass computes the elapsed measures, a separate reduction counts successes, and the empty elapsed population is answered before the loop.
21
+ * @evidence contracts/common.md#prohibited-implementation-shortcuts The method is the recognized single-pass algorithm rather than a compensating clamp.
22
+ * @evidence contracts/common.md#meaningful-documentation The comment states the unit, the empty-set convention, and the algorithm.
23
+ */
24
+ const of: (events: IBenchmarkEvent[]) => DynamicBenchmarker.IReport.IStatistics;
25
+ }
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DynamicBenchmarkStatistics = void 0;
4
+ /**
5
+ * Statistics of benchmarked events.
6
+ *
7
+ * @evidence contracts/common.md#principled-implementation The success count uses one reduction without retaining a filtered event array, while mean, population standard deviation, minimum and maximum share one pass over event start/completion durations. Both operations are linear in the event population.
8
+ * @evidence contracts/common.md#clear-and-simple-design One namespace with one exported function; the elapsed-time measures are a private helper of it.
9
+ * @evidence contracts/common.md#prohibited-implementation-shortcuts The formulas are standard statistics without tuning to any benchmark result.
10
+ * @evidence contracts/common.md#meaningful-documentation The comment states its single job.
11
+ */
12
+ var DynamicBenchmarkStatistics;
13
+ (function (DynamicBenchmarkStatistics) {
14
+ /**
15
+ * Summarizes events into counts and elapsed-time statistics.
16
+ *
17
+ * Durations are milliseconds. The empty set has `null` measures, and the
18
+ * standard deviation is the population deviation computed with Welford's
19
+ * update.
20
+ *
21
+ * @evidence contracts/common.md#principled-implementation Welford's update accumulates deviations from a running mean, avoiding the subtraction of nearly equal large squared averages that caused cancellation in constant durations. The variance divisor is the population count; floating-point arithmetic remains approximate rather than a claim of exact arithmetic for every possible input.
22
+ * @evidence contracts/common.md#clear-and-simple-design One shared pass computes the elapsed measures, a separate reduction counts successes, and the empty elapsed population is answered before the loop.
23
+ * @evidence contracts/common.md#prohibited-implementation-shortcuts The method is the recognized single-pass algorithm rather than a compensating clamp.
24
+ * @evidence contracts/common.md#meaningful-documentation The comment states the unit, the empty-set convention, and the algorithm.
25
+ */
26
+ DynamicBenchmarkStatistics.of = (events) => (Object.assign({ count: events.length, success: events.reduce((count, event) => count + Number(event.success), 0) }, elapsed(events)));
27
+ const elapsed = (events) => {
28
+ if (events.length === 0)
29
+ return { mean: null, stdev: null, minimum: null, maximum: null };
30
+ // Welford's single pass keeps the sum of squared deviations from the
31
+ // running mean, so it stays non-negative where the difference between the
32
+ // mean of squares and the squared mean cancels to a negative value and the
33
+ // square root returns NaN.
34
+ let count = 0;
35
+ let mean = 0;
36
+ let deviations = 0;
37
+ let minimum = Number.POSITIVE_INFINITY;
38
+ let maximum = Number.NEGATIVE_INFINITY;
39
+ for (const event of events) {
40
+ const value = new Date(event.completed_at).getTime() -
41
+ new Date(event.started_at).getTime();
42
+ const delta = value - mean;
43
+ mean += delta / ++count;
44
+ deviations += delta * (value - mean);
45
+ minimum = Math.min(minimum, value);
46
+ maximum = Math.max(maximum, value);
47
+ }
48
+ return { mean, stdev: Math.sqrt(deviations / count), minimum, maximum };
49
+ };
50
+ })(DynamicBenchmarkStatistics || (exports.DynamicBenchmarkStatistics = DynamicBenchmarkStatistics = {}));
51
+ //# sourceMappingURL=DynamicBenchmarkStatistics.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DynamicBenchmarkStatistics.js","sourceRoot":"","sources":["../../src/internal/DynamicBenchmarkStatistics.ts"],"names":[],"mappings":";;;AAGA;;;;;;;GAOG;AACH,IAAiB,0BAA0B,CAkD1C;AAlDD,WAAiB,0BAA0B;IACzC;;;;;;;;;;;OAWG;IACU,6BAAE,GAAG,CAChB,MAAyB,EACe,EAAE,CAAC,iBAC3C,KAAK,EAAE,MAAM,CAAC,MAAM,EACpB,OAAO,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE,CAAC,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,IACvE,OAAO,CAAC,MAAM,CAAC,EAClB,CAAC;IAEH,MAAM,OAAO,GAAG,CACd,MAAyB,EAIzB,EAAE;QACF,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC;YACrB,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;QACnE,qEAAqE;QACrE,0EAA0E;QAC1E,2EAA2E;QAC3E,2BAA2B;QAC3B,IAAI,KAAK,GAAW,CAAC,CAAC;QACtB,IAAI,IAAI,GAAW,CAAC,CAAC;QACrB,IAAI,UAAU,GAAW,CAAC,CAAC;QAC3B,IAAI,OAAO,GAAW,MAAM,CAAC,iBAAiB,CAAC;QAC/C,IAAI,OAAO,GAAW,MAAM,CAAC,iBAAiB,CAAC;QAC/C,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;YAC3B,MAAM,KAAK,GACT,IAAI,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC,OAAO,EAAE;gBACtC,IAAI,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,OAAO,EAAE,CAAC;YACvC,MAAM,KAAK,GAAW,KAAK,GAAG,IAAI,CAAC;YACnC,IAAI,IAAI,KAAK,GAAG,EAAE,KAAK,CAAC;YACxB,UAAU,IAAI,KAAK,GAAG,CAAC,KAAK,GAAG,IAAI,CAAC,CAAC;YACrC,OAAO,GAAG,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;YACnC,OAAO,GAAG,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;QACrC,CAAC;QACD,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,CAAC,IAAI,CAAC,UAAU,GAAG,KAAK,CAAC,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC;IAC1E,CAAC,CAAC;AACJ,CAAC,EAlDgB,0BAA0B,aAA1B,0BAA0B,GAA1B,0BAA0B,QAkD1C"}
@@ -1,4 +1,30 @@
1
+ /**
2
+ * The operations a servant may call on the master through the worker
3
+ * connection.
4
+ *
5
+ * @evidence contracts/common.md#principled-implementation The interface lists the two calls the servant makes back to the master: whether to load a file and how many benchmark function invocations have completed.
6
+ * @evidence contracts/common.md#clear-and-simple-design Two members, one per callback, with no behavior in the type.
7
+ * @evidence contracts/common.md#prohibited-implementation-shortcuts It is the RPC contract of the master, not a test-specific seam.
8
+ * @evidence contracts/common.md#meaningful-documentation The comment states which side implements it.
9
+ */
1
10
  export interface IBenchmarkMaster {
11
+ /**
12
+ * Asks the master whether a benchmark file, by basename, may be imported.
13
+ *
14
+ * @evidence contracts/common.md#principled-implementation The servant asks before every import so the master's predicate decides which modules load.
15
+ * @evidence contracts/common.md#clear-and-simple-design One predicate over a file name.
16
+ * @evidence contracts/common.md#prohibited-implementation-shortcuts The answer is the caller's filter, not a fixed list.
17
+ * @evidence contracts/common.md#meaningful-documentation The comment states the argument and the meaning of the answer.
18
+ */
2
19
  filter: (file: string) => boolean;
20
+ /**
21
+ * Reports the number of benchmark function invocations this servant has
22
+ * completed so far, independently of logged HTTP event count.
23
+ *
24
+ * @evidence contracts/common.md#principled-implementation A servant reports its own cumulative count, and the master sums the servants' counts.
25
+ * @evidence contracts/common.md#clear-and-simple-design One notification with one number.
26
+ * @evidence contracts/common.md#prohibited-implementation-shortcuts The count is measured by the servant, not estimated.
27
+ * @evidence contracts/common.md#meaningful-documentation The comment states that the value is cumulative and per servant.
28
+ */
3
29
  progress: (current: number) => void;
4
30
  }
@@ -1,5 +1,24 @@
1
1
  import { IBenchmarkEvent } from "../IBenchmarkEvent";
2
+ /**
3
+ * The operations the master may call on a servant through the worker
4
+ * connection.
5
+ *
6
+ * @evidence contracts/common.md#principled-implementation The interface lists the one call the master makes: run a share of benchmark function invocations and return their logged HTTP events.
7
+ * @evidence contracts/common.md#clear-and-simple-design One member, no behavior in the type.
8
+ * @evidence contracts/common.md#prohibited-implementation-shortcuts It is the RPC contract of the servant, not a test-specific seam.
9
+ * @evidence contracts/common.md#meaningful-documentation The comment states which side implements it.
10
+ */
2
11
  export interface IBenchmarkServant {
12
+ /**
13
+ * Runs the requested number of benchmark function invocations with the given
14
+ * simultaneous budget and returns every logged HTTP event. One invocation can
15
+ * log zero, one or several events.
16
+ *
17
+ * @evidence contracts/common.md#principled-implementation The master gives each servant its share of the count and of the simultaneous budget, and the servant returns the events for its share.
18
+ * @evidence contracts/common.md#clear-and-simple-design One request-response operation with two numbers in and events out.
19
+ * @evidence contracts/common.md#prohibited-implementation-shortcuts The servant runs what the master assigned, without adjusting the budget.
20
+ * @evidence contracts/common.md#meaningful-documentation The comment states the arguments and the returned events.
21
+ */
3
22
  execute(props: {
4
23
  count: number;
5
24
  simultaneous: number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nestia/benchmark",
3
- "version": "14.0.1",
3
+ "version": "14.0.2",
4
4
  "description": "NestJS Performance Benchmark Program",
5
5
  "main": "lib/index.js",
6
6
  "exports": {
@@ -30,7 +30,7 @@
30
30
  "dependencies": {
31
31
  "tgrid": "^1.2.1",
32
32
  "tstl": "^3.0.0",
33
- "@nestia/fetcher": "^14.0.1"
33
+ "@nestia/fetcher": "^14.0.2"
34
34
  },
35
35
  "devDependencies": {
36
36
  "@types/node": "^25.3.3",
@@ -48,7 +48,8 @@
48
48
  },
49
49
  "scripts": {
50
50
  "build": "rimraf lib && ttsc",
51
- "dev": "rimraf lib && ttsc --watch"
51
+ "dev": "rimraf lib && ttsc --watch",
52
+ "evidence": "evidence"
52
53
  },
53
54
  "types": "lib/index.d.ts"
54
55
  }