forked from mrmlnc/fast-glob
-
Notifications
You must be signed in to change notification settings - Fork 0
/
herebyfile.mjs
85 lines (73 loc) · 3.02 KB
/
herebyfile.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import { execa } from 'execa';
import { task } from 'hereby';
const CONCURRENCY = process.env.CONCURRENCY === '1';
const REPORTER = process.env.REPORTER ?? 'compact';
const WARMUP_COUNT = process.env.WARMUP_COUNT ?? 50;
const RUNS_COUNT = process.env.RUNS_COUNT ?? 100;
const PRODUCT_ASYNC_SUITE = './out/benchmark/suites/product/async.js';
const PRODUCT_SYNC_SUITE = './out/benchmark/suites/product/sync.js';
const PRODUCT_STREAM_SUITE = './out/benchmark/suites/product/stream.js';
const REGRESSION_ASYNC_SUITE = './out/benchmark/suites/regression/async.js';
const REGRESSION_SYNC_SUITE = './out/benchmark/suites/regression/sync.js';
const REGRESSION_STREAM_SUITE = './out/benchmark/suites/regression/stream.js';
const FLATTEN_PATTERN = '*';
const DEEP_PATTERN = '**';
const PARTIAL_FLATTEN_PATTERN = '{fixtures,out}/{first,second}/*';
const PARTIAL_DEEP_PATTERN = '{fixtures,out}/**';
async function benchTask(suite, label, pattern, implementations = []) {
await execa('bencho', [
`'node ${suite} . "${pattern}" {impl}'`,
`-n "${label} {impl} ${pattern}"`,
`-w ${WARMUP_COUNT}`,
`-r ${RUNS_COUNT}`,
`-l impl=${implementations.join()}`,
`--reporter=${REPORTER}`
], {
shell: true,
stdout: 'inherit'
});
}
function makeBenchSuiteTask(type, label, suite, implementations = []) {
const asyncFlattenTask = task({
name: `bench:${type}:${label}:flatten`,
run: () => benchTask(suite, 'async', FLATTEN_PATTERN, implementations)
});
const asyncDeepTask = task({
name: `bench:${type}:${label}:deep`,
dependencies: CONCURRENCY ? [] : [asyncFlattenTask],
run: () => benchTask(suite, 'async', DEEP_PATTERN, implementations)
});
const asyncPartialFlattenTask = task({
name: `bench:${type}:${label}:partial_flatten`,
dependencies: CONCURRENCY ? [] : [asyncDeepTask],
run: () => benchTask(suite, 'async', PARTIAL_FLATTEN_PATTERN, implementations)
});
const asyncPartialDeepTask = task({
name: `bench:${type}:${label}:partial_deep`,
dependencies: CONCURRENCY ? [] : [asyncPartialFlattenTask],
run: () => benchTask(suite, 'async', PARTIAL_DEEP_PATTERN, implementations)
});
return task({
name: `bench:${type}:${label}`,
dependencies: CONCURRENCY ? [] : [asyncPartialDeepTask],
run: () => {}
});
}
export const {
productAsyncTask,
productStreamTask,
productSyncTask
} = {
productAsyncTask: makeBenchSuiteTask('product', 'async', PRODUCT_ASYNC_SUITE, ['fast-glob', 'node-glob', 'fdir']),
productStreamTask: makeBenchSuiteTask('product', 'stream', PRODUCT_STREAM_SUITE, ['fast-glob', 'node-glob']),
productSyncTask: makeBenchSuiteTask('product', 'sync', PRODUCT_SYNC_SUITE, ['fast-glob', 'node-glob', 'fdir'])
};
export const {
regressionAsyncTask,
regressionStreamTask,
regressionSyncTask
} = {
regressionAsyncTask: makeBenchSuiteTask('regression', 'async', REGRESSION_ASYNC_SUITE, ['current', 'previous']),
regressionStreamTask: makeBenchSuiteTask('regression', 'stream', REGRESSION_STREAM_SUITE, ['current', 'previous']),
regressionSyncTask: makeBenchSuiteTask('regression', 'sync', REGRESSION_SYNC_SUITE, ['current', 'previous'])
};