overtake 1.0.0-rc.2 → 1.0.0-rc.3
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/build/cli.cjs +7 -7
- package/build/cli.cjs.map +1 -1
- package/build/cli.js +1 -1
- package/build/cli.js.map +1 -1
- package/build/index.cjs +228 -11
- package/build/index.cjs.map +1 -1
- package/build/index.d.ts +65 -3
- package/build/index.js +187 -1
- package/build/index.js.map +1 -1
- package/build/reporter.cjs +1 -1
- package/build/reporter.cjs.map +1 -1
- package/build/reporter.js +1 -1
- package/build/reporter.js.map +1 -1
- package/examples/array-copy.ts +17 -0
- package/package.json +1 -1
- package/src/cli.ts +2 -2
- package/src/index.ts +232 -3
- package/src/reporter.ts +1 -1
- package/build/__tests__/runner.d.ts +0 -1
- package/build/benchmark.cjs +0 -237
- package/build/benchmark.cjs.map +0 -1
- package/build/benchmark.d.ts +0 -64
- package/build/benchmark.js +0 -189
- package/build/benchmark.js.map +0 -1
- package/overtakes/array-copy.md +0 -80
- package/overtakes/array-delete-element.md +0 -44
- package/overtakes/async.md +0 -25
- package/overtakes/class-vs-function.md +0 -31
- package/overtakes/postgres-vs-mongo.md +0 -55
- package/src/__tests__/runner.ts +0 -34
- package/src/benchmark.ts +0 -231
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
# Array delete element
|
|
2
|
-
|
|
3
|
-
```
|
|
4
|
-
⭐ Script __benchmarks__/array-delete-element.js
|
|
5
|
-
⇶ Suite Array delete element methods
|
|
6
|
-
➤ Perform 10 elements
|
|
7
|
-
✓ Measure 500000 splice
|
|
8
|
-
┌──────────┬──────────┬──────────┬──────────┬───────────┬────────┐
|
|
9
|
-
│ (index) │ med │ p95 │ p99 │ total │ count │
|
|
10
|
-
├──────────┼──────────┼──────────┼──────────┼───────────┼────────┤
|
|
11
|
-
│ 0.000072 │ 0.000078 │ 0.000121 │ 0.000248 │ 57.628642 │ 500000 │
|
|
12
|
-
└──────────┴──────────┴──────────┴──────────┴───────────┴────────┘
|
|
13
|
-
✓ Measure 500000 filter
|
|
14
|
-
┌──────────┬──────────┬─────────┬──────────┬───────────┬────────┐
|
|
15
|
-
│ (index) │ med │ p95 │ p99 │ total │ count │
|
|
16
|
-
├──────────┼──────────┼─────────┼──────────┼───────────┼────────┤
|
|
17
|
-
│ 0.000067 │ 0.000077 │ 0.00018 │ 0.000303 │ 51.695539 │ 500000 │
|
|
18
|
-
└──────────┴──────────┴─────────┴──────────┴───────────┴────────┘
|
|
19
|
-
✓ Measure 500000 for loop
|
|
20
|
-
┌──────────┬──────────┬──────────┬──────────┬───────────┬────────┐
|
|
21
|
-
│ (index) │ med │ p95 │ p99 │ total │ count │
|
|
22
|
-
├──────────┼──────────┼──────────┼──────────┼───────────┼────────┤
|
|
23
|
-
│ 0.000064 │ 0.000074 │ 0.000119 │ 0.000307 │ 44.446428 │ 500000 │
|
|
24
|
-
└──────────┴──────────┴──────────┴──────────┴───────────┴────────┘
|
|
25
|
-
➤ Perform 1000 elements
|
|
26
|
-
✓ Measure 500000 splice
|
|
27
|
-
┌─────────┬──────────┬──────────┬──────────┬───────────┬────────┐
|
|
28
|
-
│ (index) │ med │ p95 │ p99 │ total │ count │
|
|
29
|
-
├─────────┼──────────┼──────────┼──────────┼───────────┼────────┤
|
|
30
|
-
│ 0.00007 │ 0.000076 │ 0.000121 │ 0.000268 │ 54.328497 │ 500000 │
|
|
31
|
-
└─────────┴──────────┴──────────┴──────────┴───────────┴────────┘
|
|
32
|
-
✓ Measure 500000 filter
|
|
33
|
-
┌──────────┬──────────┬──────────┬─────────┬────────────┬────────┐
|
|
34
|
-
│ (index) │ med │ p95 │ p99 │ total │ count │
|
|
35
|
-
├──────────┼──────────┼──────────┼─────────┼────────────┼────────┤
|
|
36
|
-
│ 0.002064 │ 0.002521 │ 0.003448 │ 0.00804 │ 1571.98239 │ 500000 │
|
|
37
|
-
└──────────┴──────────┴──────────┴─────────┴────────────┴────────┘
|
|
38
|
-
✓ Measure 500000 for loop
|
|
39
|
-
┌──────────┬──────────┬──────────┬─────────┬─────────────┬────────┐
|
|
40
|
-
│ (index) │ med │ p95 │ p99 │ total │ count │
|
|
41
|
-
├──────────┼──────────┼──────────┼─────────┼─────────────┼────────┤
|
|
42
|
-
│ 0.002166 │ 0.002625 │ 0.003383 │ 0.00448 │ 1578.507514 │ 500000 │
|
|
43
|
-
└──────────┴──────────┴──────────┴─────────┴─────────────┴────────┘
|
|
44
|
-
```
|
package/overtakes/async.md
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
# Async functions call performance
|
|
2
|
-
|
|
3
|
-
```
|
|
4
|
-
⭐ Script __benchmarks__/async.js
|
|
5
|
-
⇶ Suite Async functions performance
|
|
6
|
-
➤ Perform 10000000 calls
|
|
7
|
-
✓ Measure 10000000 calls of function that returns Promise.resolve()
|
|
8
|
-
┌─────────┬──────────┬──────────┬─────────┬─────────────┬──────────┐
|
|
9
|
-
│ (index) │ med │ p95 │ p99 │ total │ count │
|
|
10
|
-
├─────────┼──────────┼──────────┼─────────┼─────────────┼──────────┤
|
|
11
|
-
│ 0.00008 │ 0.000093 │ 0.000138 │ 0.00023 │ 1189.475052 │ 10000000 │
|
|
12
|
-
└─────────┴──────────┴──────────┴─────────┴─────────────┴──────────┘
|
|
13
|
-
✓ Measure 10000000 calls of async function that returns await Promise.resolve()
|
|
14
|
-
┌──────────┬──────────┬──────────┬──────────┬─────────────┬──────────┐
|
|
15
|
-
│ (index) │ med │ p95 │ p99 │ total │ count │
|
|
16
|
-
├──────────┼──────────┼──────────┼──────────┼─────────────┼──────────┤
|
|
17
|
-
│ 0.000108 │ 0.000122 │ 0.000267 │ 0.000389 │ 1735.581918 │ 10000000 │
|
|
18
|
-
└──────────┴──────────┴──────────┴──────────┴─────────────┴──────────┘
|
|
19
|
-
✓ Measure 10000000 calls of async function that returns Promise.resolve()
|
|
20
|
-
┌──────────┬──────────┬──────────┬──────────┬─────────────┬──────────┐
|
|
21
|
-
│ (index) │ med │ p95 │ p99 │ total │ count │
|
|
22
|
-
├──────────┼──────────┼──────────┼──────────┼─────────────┼──────────┤
|
|
23
|
-
│ 0.000105 │ 0.000125 │ 0.000203 │ 0.000333 │ 1557.773513 │ 10000000 │
|
|
24
|
-
└──────────┴──────────┴──────────┴──────────┴─────────────┴──────────┘
|
|
25
|
-
```
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
# Class vs Function
|
|
2
|
-
|
|
3
|
-
```
|
|
4
|
-
⭐ Script __benchmarks__/class-vs-function.js
|
|
5
|
-
⇶ Suite Class vs Function
|
|
6
|
-
➤ Perform Instantiation
|
|
7
|
-
✓ Measure 1000000 class declarations via "class"
|
|
8
|
-
┌──────────┬──────────┬──────────┬──────────┬───────────┬─────────┐
|
|
9
|
-
│ (index) │ med │ p95 │ p99 │ total │ count │
|
|
10
|
-
├──────────┼──────────┼──────────┼──────────┼───────────┼─────────┤
|
|
11
|
-
│ 0.000438 │ 0.000496 │ 0.001133 │ 0.001602 │ 684.87052 │ 1000000 │
|
|
12
|
-
└──────────┴──────────┴──────────┴──────────┴───────────┴─────────┘
|
|
13
|
-
✓ Measure 1000000 instantiations of the declared class via class and test method call
|
|
14
|
-
┌──────────┬──────────┬──────────┬──────────┬───────────┬─────────┐
|
|
15
|
-
│ (index) │ med │ p95 │ p99 │ total │ count │
|
|
16
|
-
├──────────┼──────────┼──────────┼──────────┼───────────┼─────────┤
|
|
17
|
-
│ 0.000048 │ 0.000054 │ 0.000059 │ 0.000137 │ 61.055298 │ 1000000 │
|
|
18
|
-
└──────────┴──────────┴──────────┴──────────┴───────────┴─────────┘
|
|
19
|
-
✓ Measure 1000000 class declarations via function
|
|
20
|
-
┌─────────┬──────────┬─────────┬──────────┬──────────┬─────────┐
|
|
21
|
-
│ (index) │ med │ p95 │ p99 │ total │ count │
|
|
22
|
-
├─────────┼──────────┼─────────┼──────────┼──────────┼─────────┤
|
|
23
|
-
│ 0.00005 │ 0.000056 │ 0.00007 │ 0.000146 │ 63.94922 │ 1000000 │
|
|
24
|
-
└─────────┴──────────┴─────────┴──────────┴──────────┴─────────┘
|
|
25
|
-
✓ Measure 1000000 instantiations of the declared class via function and test method call
|
|
26
|
-
┌──────────┬──────────┬─────────┬──────────┬───────────┬─────────┐
|
|
27
|
-
│ (index) │ med │ p95 │ p99 │ total │ count │
|
|
28
|
-
├──────────┼──────────┼─────────┼──────────┼───────────┼─────────┤
|
|
29
|
-
│ 0.000049 │ 0.000056 │ 0.00008 │ 0.000189 │ 78.511849 │ 1000000 │
|
|
30
|
-
└──────────┴──────────┴─────────┴──────────┴───────────┴─────────┘
|
|
31
|
-
```
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
### Postgres vs MongoDB
|
|
2
|
-
|
|
3
|
-
```
|
|
4
|
-
⭐ Script __benchmarks__/postgres-vs-mongo.js
|
|
5
|
-
⇶ Suite mongodb vs postgres
|
|
6
|
-
➤ Perform simple test
|
|
7
|
-
✓ Measure 1000 postgres inserts
|
|
8
|
-
┌──────────┬──────────┬──────────┬─────────┬─────────────┬───────┐
|
|
9
|
-
│ (index) │ med │ p95 │ p99 │ total │ count │
|
|
10
|
-
├──────────┼──────────┼──────────┼─────────┼─────────────┼───────┤
|
|
11
|
-
│ 2.232527 │ 2.256009 │ 2.917856 │ 5.41444 │ 2408.708534 │ 1000 │
|
|
12
|
-
└──────────┴──────────┴──────────┴─────────┴─────────────┴───────┘
|
|
13
|
-
✓ Measure 1000 mongodb inserts
|
|
14
|
-
┌──────────┬──────────┬──────────┬──────────┬─────────────┬───────┐
|
|
15
|
-
│ (index) │ med │ p95 │ p99 │ total │ count │
|
|
16
|
-
├──────────┼──────────┼──────────┼──────────┼─────────────┼───────┤
|
|
17
|
-
│ 2.955035 │ 2.981828 │ 5.038826 │ 5.467477 │ 3233.680552 │ 1000 │
|
|
18
|
-
└──────────┴──────────┴──────────┴──────────┴─────────────┴───────┘
|
|
19
|
-
✓ Measure 1000 postgres query data
|
|
20
|
-
┌─────────┬──────────┬──────────┬──────────┬────────────┬───────┐
|
|
21
|
-
│ (index) │ med │ p95 │ p99 │ total │ count │
|
|
22
|
-
├─────────┼──────────┼──────────┼──────────┼────────────┼───────┤
|
|
23
|
-
│ 0.28218 │ 0.297544 │ 0.393615 │ 0.561729 │ 308.713494 │ 1000 │
|
|
24
|
-
└─────────┴──────────┴──────────┴──────────┴────────────┴───────┘
|
|
25
|
-
✓ Measure 1000 mongodb query data
|
|
26
|
-
┌──────────┬──────────┬──────────┬──────────┬───────────┬───────┐
|
|
27
|
-
│ (index) │ med │ p95 │ p99 │ total │ count │
|
|
28
|
-
├──────────┼──────────┼──────────┼──────────┼───────────┼───────┤
|
|
29
|
-
│ 0.457289 │ 0.461665 │ 0.693627 │ 0.919116 │ 495.27099 │ 1000 │
|
|
30
|
-
└──────────┴──────────┴──────────┴──────────┴───────────┴───────┘
|
|
31
|
-
✓ Measure 1000 postgres query inserts
|
|
32
|
-
┌──────────┬──────────┬──────────┬──────────┬─────────────┬───────┐
|
|
33
|
-
│ (index) │ med │ p95 │ p99 │ total │ count │
|
|
34
|
-
├──────────┼──────────┼──────────┼──────────┼─────────────┼───────┤
|
|
35
|
-
│ 2.491574 │ 2.500577 │ 3.524734 │ 6.177946 │ 2681.101875 │ 1000 │
|
|
36
|
-
└──────────┴──────────┴──────────┴──────────┴─────────────┴───────┘
|
|
37
|
-
✓ Measure 1000 mongodb query inserts
|
|
38
|
-
┌──────────┬──────────┬──────────┬─────────┬─────────────┬───────┐
|
|
39
|
-
│ (index) │ med │ p95 │ p99 │ total │ count │
|
|
40
|
-
├──────────┼──────────┼──────────┼─────────┼─────────────┼───────┤
|
|
41
|
-
│ 3.946823 │ 3.921073 │ 5.969672 │ 6.26903 │ 3954.008642 │ 1000 │
|
|
42
|
-
└──────────┴──────────┴──────────┴─────────┴─────────────┴───────┘
|
|
43
|
-
✓ Measure 1000 postgres group data
|
|
44
|
-
┌──────────┬──────────┬──────────┬──────────┬────────────┬───────┐
|
|
45
|
-
│ (index) │ med │ p95 │ p99 │ total │ count │
|
|
46
|
-
├──────────┼──────────┼──────────┼──────────┼────────────┼───────┤
|
|
47
|
-
│ 0.287954 │ 0.272375 │ 0.347489 │ 0.494122 │ 279.076014 │ 1000 │
|
|
48
|
-
└──────────┴──────────┴──────────┴──────────┴────────────┴───────┘
|
|
49
|
-
✓ Measure 1000 mongodb group data
|
|
50
|
-
┌──────────┬──────────┬──────────┬──────────┬────────────┬───────┐
|
|
51
|
-
│ (index) │ med │ p95 │ p99 │ total │ count │
|
|
52
|
-
├──────────┼──────────┼──────────┼──────────┼────────────┼───────┤
|
|
53
|
-
│ 0.564809 │ 0.556707 │ 0.666702 │ 0.851308 │ 569.134585 │ 1000 │
|
|
54
|
-
└──────────┴──────────┴──────────┴──────────┴────────────┴───────┘
|
|
55
|
-
```
|
package/src/__tests__/runner.ts
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { Benchmark } from '../benchmark.js';
|
|
2
|
-
|
|
3
|
-
const benchmark = Benchmark.create('void')
|
|
4
|
-
.feed('strings', () => ['a', 'b', 'c'])
|
|
5
|
-
.feed('numbers', () => [0, 1, 2]);
|
|
6
|
-
|
|
7
|
-
const httpServer = benchmark.target('node http', async () => {
|
|
8
|
-
const { createServer, Server } = await import('node:http');
|
|
9
|
-
const server = createServer();
|
|
10
|
-
return new Promise<InstanceType<typeof Server>>((resolve) => {
|
|
11
|
-
server.on('listen', () => resolve(server));
|
|
12
|
-
});
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
httpServer.teardown((ctx) => {
|
|
16
|
-
ctx.close();
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
httpServer
|
|
20
|
-
.measure('something to bench', async (ctx, input) => {
|
|
21
|
-
ctx.emit('whatever', input);
|
|
22
|
-
})
|
|
23
|
-
.pre(async (ctx, input) => {})
|
|
24
|
-
.post(async (ctx, input) => {});
|
|
25
|
-
|
|
26
|
-
const forLoop = benchmark.target('for loop');
|
|
27
|
-
|
|
28
|
-
forLoop
|
|
29
|
-
.measure('1k', (_, input) => {
|
|
30
|
-
const n = input?.length ?? 0;
|
|
31
|
-
for (let i = 0; i < n; i++) {}
|
|
32
|
-
})
|
|
33
|
-
.pre(async (ctx, input) => {})
|
|
34
|
-
.post(async (ctx, input) => {});
|
package/src/benchmark.ts
DELETED
|
@@ -1,231 +0,0 @@
|
|
|
1
|
-
import { cpus } from 'node:os';
|
|
2
|
-
import { createExecutor, ExecutorOptions, ExecutorReport } from './executor.js';
|
|
3
|
-
import { MaybePromise, StepFn, SetupFn, TeardownFn, FeedFn, ReportType, ReportTypeList, DEFAULT_CYCLES } from './types.js';
|
|
4
|
-
|
|
5
|
-
export const DEFAULT_WORKERS = cpus().length;
|
|
6
|
-
|
|
7
|
-
export const AsyncFunction = (async () => {}).constructor;
|
|
8
|
-
|
|
9
|
-
export interface TargetReport<R extends ReportTypeList> {
|
|
10
|
-
target: string;
|
|
11
|
-
measures: MeasureReport<R>[];
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export interface MeasureReport<R extends ReportTypeList> {
|
|
15
|
-
measure: string;
|
|
16
|
-
feeds: FeedReport<R>[];
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export interface FeedReport<R extends ReportTypeList> {
|
|
20
|
-
feed: string;
|
|
21
|
-
data: ExecutorReport<R>;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export const DEFAULT_REPORT_TYPES = ['ops'] as const;
|
|
25
|
-
export type DefaultReportTypes = (typeof DEFAULT_REPORT_TYPES)[number];
|
|
26
|
-
|
|
27
|
-
export class MeasureContext<TContext, TInput> {
|
|
28
|
-
public pre?: StepFn<TContext, TInput>;
|
|
29
|
-
public post?: StepFn<TContext, TInput>;
|
|
30
|
-
|
|
31
|
-
constructor(
|
|
32
|
-
public title: string,
|
|
33
|
-
public run: StepFn<TContext, TInput>,
|
|
34
|
-
) {}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export class Measure<TContext, TInput> {
|
|
38
|
-
#ctx: MeasureContext<TContext, TInput>;
|
|
39
|
-
|
|
40
|
-
constructor(ctx: MeasureContext<TContext, TInput>) {
|
|
41
|
-
this.#ctx = ctx;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
pre(fn: StepFn<TContext, TInput>): Measure<TContext, TInput> {
|
|
45
|
-
this.#ctx.pre = fn;
|
|
46
|
-
return this;
|
|
47
|
-
}
|
|
48
|
-
post(fn: StepFn<TContext, TInput>): Measure<TContext, TInput> {
|
|
49
|
-
this.#ctx.post = fn;
|
|
50
|
-
return this;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
export class TargetContext<TContext, TInput> {
|
|
55
|
-
public teardown?: TeardownFn<TContext>;
|
|
56
|
-
public measures: MeasureContext<TContext, TInput>[] = [];
|
|
57
|
-
|
|
58
|
-
constructor(
|
|
59
|
-
readonly title: string,
|
|
60
|
-
readonly setup?: SetupFn<MaybePromise<TContext>>,
|
|
61
|
-
) {}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
export class Target<TContext, TInput> {
|
|
65
|
-
#ctx: TargetContext<TContext, TInput>;
|
|
66
|
-
|
|
67
|
-
constructor(ctx: TargetContext<TContext, TInput>) {
|
|
68
|
-
this.#ctx = ctx;
|
|
69
|
-
}
|
|
70
|
-
teardown(fn: TeardownFn<TContext>): Target<TContext, TInput> {
|
|
71
|
-
this.#ctx.teardown = fn;
|
|
72
|
-
|
|
73
|
-
return this;
|
|
74
|
-
}
|
|
75
|
-
measure(title: string, run: StepFn<TContext, TInput>): Measure<TContext, TInput> {
|
|
76
|
-
const measure = new MeasureContext(title, run);
|
|
77
|
-
this.#ctx.measures.push(measure);
|
|
78
|
-
|
|
79
|
-
return new Measure(measure);
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
export class FeedContext<TInput> {
|
|
84
|
-
constructor(
|
|
85
|
-
readonly title: string,
|
|
86
|
-
readonly fn?: FeedFn<TInput>,
|
|
87
|
-
) {}
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
export class Benchmark<TInput> {
|
|
91
|
-
#targets: TargetContext<unknown, TInput>[] = [];
|
|
92
|
-
#feeds: FeedContext<TInput>[] = [];
|
|
93
|
-
#executed = false;
|
|
94
|
-
|
|
95
|
-
static create(title: string): Benchmark<void>;
|
|
96
|
-
static create<I>(title: string, fn: FeedFn<I>): Benchmark<I>;
|
|
97
|
-
static create<I>(title: string, fn?: FeedFn<I> | undefined): Benchmark<I> {
|
|
98
|
-
if (fn) {
|
|
99
|
-
return new Benchmark(title, fn);
|
|
100
|
-
} else {
|
|
101
|
-
return new Benchmark(title);
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
constructor(title: string);
|
|
106
|
-
constructor(title: string, fn: FeedFn<TInput>);
|
|
107
|
-
constructor(title: string, fn?: FeedFn<TInput> | undefined) {
|
|
108
|
-
if (fn) {
|
|
109
|
-
this.feed(title, fn);
|
|
110
|
-
} else {
|
|
111
|
-
this.feed(title);
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
feed(title: string): Benchmark<TInput | void>;
|
|
116
|
-
feed<I>(title: string, fn: FeedFn<I>): Benchmark<TInput | I>;
|
|
117
|
-
feed<I>(title: string, fn?: FeedFn<I> | undefined): Benchmark<TInput | I> {
|
|
118
|
-
const self = this as Benchmark<TInput | I>;
|
|
119
|
-
self.#feeds.push(fn ? new FeedContext(title, fn) : new FeedContext(title));
|
|
120
|
-
|
|
121
|
-
return self;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
target<TContext>(title: string): Target<void, TInput>;
|
|
125
|
-
target<TContext>(title: string, setup: SetupFn<Awaited<TContext>>): Target<TContext, TInput>;
|
|
126
|
-
target<TContext>(title: string, setup?: SetupFn<Awaited<TContext>> | undefined): Target<TContext, TInput> {
|
|
127
|
-
const target = new TargetContext<TContext, TInput>(title, setup);
|
|
128
|
-
this.#targets.push(target as TargetContext<unknown, TInput>);
|
|
129
|
-
|
|
130
|
-
return new Target<TContext, TInput>(target);
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
async execute<R extends readonly ReportType[] = typeof DEFAULT_REPORT_TYPES>({
|
|
134
|
-
workers = DEFAULT_WORKERS,
|
|
135
|
-
warmupCycles = 20,
|
|
136
|
-
maxCycles = DEFAULT_CYCLES,
|
|
137
|
-
minCycles = 50,
|
|
138
|
-
absThreshold = 1_000,
|
|
139
|
-
relThreshold = 0.02,
|
|
140
|
-
reportTypes = DEFAULT_REPORT_TYPES as unknown as R,
|
|
141
|
-
}: ExecutorOptions<R>): Promise<TargetReport<R>[]> {
|
|
142
|
-
if (this.#executed) {
|
|
143
|
-
throw new Error("Benchmark is executed and can't be reused");
|
|
144
|
-
}
|
|
145
|
-
this.#executed = true;
|
|
146
|
-
|
|
147
|
-
const executor = createExecutor<unknown, TInput, R>({
|
|
148
|
-
workers,
|
|
149
|
-
warmupCycles,
|
|
150
|
-
maxCycles,
|
|
151
|
-
minCycles,
|
|
152
|
-
absThreshold,
|
|
153
|
-
relThreshold,
|
|
154
|
-
reportTypes,
|
|
155
|
-
});
|
|
156
|
-
|
|
157
|
-
const reports: TargetReport<R>[] = [];
|
|
158
|
-
for (const target of this.#targets) {
|
|
159
|
-
const targetReport: TargetReport<R> = { target: target.title, measures: [] };
|
|
160
|
-
for (const measure of target.measures) {
|
|
161
|
-
const measureReport: MeasureReport<R> = { measure: measure.title, feeds: [] };
|
|
162
|
-
for (const feed of this.#feeds) {
|
|
163
|
-
const data = await feed.fn?.();
|
|
164
|
-
executor
|
|
165
|
-
.push<ExecutorReport<R>>({
|
|
166
|
-
setup: target.setup,
|
|
167
|
-
teardown: target.teardown,
|
|
168
|
-
pre: measure.pre,
|
|
169
|
-
run: measure.run,
|
|
170
|
-
post: measure.post,
|
|
171
|
-
data,
|
|
172
|
-
})
|
|
173
|
-
.then((data) => {
|
|
174
|
-
measureReport.feeds.push({
|
|
175
|
-
feed: feed.title,
|
|
176
|
-
data,
|
|
177
|
-
});
|
|
178
|
-
});
|
|
179
|
-
}
|
|
180
|
-
targetReport.measures.push(measureReport);
|
|
181
|
-
}
|
|
182
|
-
reports.push(targetReport);
|
|
183
|
-
}
|
|
184
|
-
await executor.drain();
|
|
185
|
-
executor.kill();
|
|
186
|
-
|
|
187
|
-
return reports;
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
export const printSimpleReports = <R extends ReportTypeList>(reports: TargetReport<R>[]) => {
|
|
192
|
-
for (const report of reports) {
|
|
193
|
-
for (const { measure, feeds } of report.measures) {
|
|
194
|
-
console.group('\n', report.target, measure);
|
|
195
|
-
for (const { feed, data } of feeds) {
|
|
196
|
-
const output = Object.entries(data)
|
|
197
|
-
.map(([key, report]) => `${key}: ${report.toString()}`)
|
|
198
|
-
.join('; ');
|
|
199
|
-
console.log(feed, output);
|
|
200
|
-
}
|
|
201
|
-
console.groupEnd();
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
};
|
|
205
|
-
|
|
206
|
-
export const printTableReports = <R extends ReportTypeList>(reports: TargetReport<R>[]) => {
|
|
207
|
-
for (const report of reports) {
|
|
208
|
-
for (const { measure, feeds } of report.measures) {
|
|
209
|
-
console.log('\n', report.target, measure);
|
|
210
|
-
const table: Record<string, unknown> = {};
|
|
211
|
-
for (const { feed, data } of feeds) {
|
|
212
|
-
table[feed] = Object.fromEntries(Object.entries(data).map(([key, report]) => [key, report.toString()]));
|
|
213
|
-
}
|
|
214
|
-
console.table(table);
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
};
|
|
218
|
-
|
|
219
|
-
export const printJSONReports = <R extends ReportTypeList>(reports: TargetReport<R>[], padding?: number) => {
|
|
220
|
-
const output = {} as Record<string, Record<string, Record<string, string>>>;
|
|
221
|
-
for (const report of reports) {
|
|
222
|
-
for (const { measure, feeds } of report.measures) {
|
|
223
|
-
const row = {} as Record<string, Record<string, string>>;
|
|
224
|
-
for (const { feed, data } of feeds) {
|
|
225
|
-
row[feed] = Object.fromEntries(Object.entries(data).map(([key, report]) => [key, report.toString()]));
|
|
226
|
-
}
|
|
227
|
-
output[`${report.target} ${measure}`] = row;
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
console.log(JSON.stringify(output, null, padding));
|
|
231
|
-
};
|