overtake 0.0.8 → 0.1.1

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/cli.js CHANGED
@@ -1,9 +1,9 @@
1
1
  #!/usr/bin/env -S node --no-warnings
2
2
 
3
- import { Command } from 'commander';
3
+ import { Command, Option } from 'commander';
4
4
  import Path from 'path';
5
- import glob from 'glob';
6
- import { load, createScript, benchmark, setup, teardown, measure, perform, run, defaultReporter } from './index.js';
5
+ import { glob } from 'glob';
6
+ import { load, createScript, benchmark, setup, teardown, measure, perform, run, defaultReporter, allowedFields } from './index.js';
7
7
  import packageJson from './package.json' assert { type: 'json' };
8
8
 
9
9
  const commands = new Command();
@@ -11,10 +11,23 @@ const commands = new Command();
11
11
  commands.name('overtake').description(packageJson.description).version(packageJson.version, '-v, --version');
12
12
 
13
13
  commands
14
- .argument('[files...]', 'file paths or path patterns to search benchmark scripts')
15
- .option('-i, --inline [inline]', 'inline code to benchmark', (value, previous) => previous.concat([value]), [])
16
- .option('-c, --count [count]', 'perform count for inline code', (v) => parseInt(v))
17
- .action(async (patterns, { count = 1, inline }) => {
14
+ .argument('[files...]', 'File paths or path patterns to search benchmark scripts')
15
+ .option('-i, --inline [inline]', 'Inline benchmark.', (value, previous) => previous.concat([value]), [])
16
+ .option('-c, --count [count]', 'Perform count for inline benchmark.', (v) => parseInt(v))
17
+ .addOption(
18
+ new Option('-f, --fields [fields]', `Comma separated list of fields to report. Allowed values are: ${allowedFields}.`)
19
+ .default(['med', 'p95', 'p99', 'sum:total', 'count'])
20
+ .argParser((fields) =>
21
+ fields.split(',').filter((field) => {
22
+ if (!allowedFields.includes(field)) {
23
+ console.error(`Invalid field name: ${field}. Allowed values are: ${allowedFields.join(', ')}.`);
24
+ process.exit(1);
25
+ }
26
+ return true;
27
+ }),
28
+ ),
29
+ )
30
+ .action(async (patterns, { count = 1, inline, fields }) => {
18
31
  Object.assign(globalThis, { benchmark, setup, teardown, measure, perform });
19
32
 
20
33
  const foundFiles = await glob(patterns);
@@ -43,7 +56,7 @@ commands
43
56
  scripts.push(script);
44
57
  }
45
58
 
46
- await run(scripts, defaultReporter);
59
+ await run(scripts, defaultReporter, fields);
47
60
  });
48
61
 
49
62
  commands.on('--help', () => {
package/index.js CHANGED
@@ -6,6 +6,32 @@ const suiteContext = createContext();
6
6
 
7
7
  export const NOOP = () => {};
8
8
 
9
+ export const allowedFields = [
10
+ 'mode',
11
+ 'med',
12
+ 'p1',
13
+ 'p5',
14
+ 'p10',
15
+ 'p20',
16
+ 'p33',
17
+ 'p50',
18
+ 'p66',
19
+ 'p80',
20
+ 'p90',
21
+ 'p95',
22
+ 'p99',
23
+ 'min',
24
+ 'max',
25
+ 'avg',
26
+ 'sum',
27
+ 'count',
28
+ 'setup',
29
+ 'init',
30
+ 'cycles',
31
+ 'teardown',
32
+ 'total',
33
+ ];
34
+
9
35
  export const setup = (fn) => {
10
36
  suiteContext.getContext().setup = fn;
11
37
  };
@@ -57,27 +83,25 @@ const map = {
57
83
  measure: '✓ Measure',
58
84
  };
59
85
 
60
- export const defaultReporter = async (type, title, test) => {
86
+ export const defaultReporter = async (type, title, test, fields) => {
61
87
  console.group(`${map[type]} ${title}`);
62
88
  await test({
63
- test: defaultReporter,
89
+ test: (...args) => defaultReporter(...args, fields),
64
90
  output: (report) =>
65
91
  console.table(
66
92
  report.success
67
93
  ? {
68
- [formatFloat(report.mode)]: {
69
- med: formatFloat(report.med),
70
- p95: formatFloat(report.p95),
71
- p99: formatFloat(report.p99),
72
- total: formatFloat(report.sum),
73
- count: report.count,
74
- },
94
+ [formatFloat(report.mode)]: fields.reduce((data, field) => {
95
+ const [key, alias = key] = field.split(':');
96
+ data[alias] = formatFloat(report[key]);
97
+ return data;
98
+ }, {}),
75
99
  }
76
100
  : {
77
101
  error: {
78
102
  reason: report.error,
79
103
  },
80
- }
104
+ },
81
105
  ),
82
106
  });
83
107
  console.groupEnd();
@@ -88,31 +112,36 @@ export function formatFloat(value, digits = ACCURACY) {
88
112
  return parseFloat(value.toFixed(digits));
89
113
  }
90
114
 
91
- export const run = async (scripts, reporter) => {
115
+ export const run = async (scripts, reporter, fields) => {
92
116
  for (const script of scripts) {
93
- await reporter('script', script.filename, async (scriptTest) => {
94
- for (const suite of script.suites) {
95
- await scriptTest.test('suite', suite.title, async (suiteTest) => {
96
- await suiteContext.contextualize(suite, suite.init);
97
- for (const perform of suite.performs) {
98
- await suiteTest.test('perform', perform.title, async (performTest) => {
99
- for (const measure of suite.measures) {
100
- await performTest.test('measure', perform.count + ' ' + measure.title, async (measureTest) => {
101
- const result = await runWorker({
102
- setup: suite.setup,
103
- teardown: suite.teardown,
104
- init: measure.init,
105
- count: perform.count,
106
- args: perform.args,
117
+ await reporter(
118
+ 'script',
119
+ script.filename,
120
+ async (scriptTest) => {
121
+ for (const suite of script.suites) {
122
+ await scriptTest.test('suite', suite.title, async (suiteTest) => {
123
+ await suiteContext.contextualize(suite, suite.init);
124
+ for (const perform of suite.performs) {
125
+ await suiteTest.test('perform', perform.title, async (performTest) => {
126
+ for (const measure of suite.measures) {
127
+ await performTest.test('measure', perform.count + ' ' + measure.title, async (measureTest) => {
128
+ const result = await runWorker({
129
+ setup: suite.setup,
130
+ teardown: suite.teardown,
131
+ init: measure.init,
132
+ count: perform.count,
133
+ args: perform.args,
134
+ });
135
+ measureTest.output(result);
107
136
  });
108
- measureTest.output(result);
109
- });
110
- }
111
- });
112
- }
113
- });
114
- }
115
- });
137
+ }
138
+ });
139
+ }
140
+ });
141
+ }
142
+ },
143
+ fields,
144
+ );
116
145
  }
117
146
  };
118
147
 
@@ -0,0 +1,25 @@
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
+ ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "overtake",
3
- "version": "0.0.8",
3
+ "version": "0.1.1",
4
4
  "description": "NodeJS performance benchmark",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -30,18 +30,18 @@
30
30
  },
31
31
  "homepage": "https://github.com/3axap4eHko/overtake#readme",
32
32
  "devDependencies": {
33
- "@jest/globals": "^29.5.0",
34
- "@types/jest": "^29.5.0",
35
- "husky": "^8.0.3",
36
- "jest": "^29.5.0",
37
- "mongodb": "^5.1.0",
38
- "pg": "^8.10.0",
39
- "prettier": "^2.8.4",
40
- "pretty-quick": "^3.1.3"
33
+ "@jest/globals": "^29.7.0",
34
+ "@types/jest": "^29.5.12",
35
+ "husky": "^9.0.11",
36
+ "jest": "^29.7.0",
37
+ "mongodb": "^6.4.0",
38
+ "pg": "^8.11.3",
39
+ "prettier": "^3.2.5",
40
+ "pretty-quick": "^4.0.0"
41
41
  },
42
42
  "dependencies": {
43
- "commander": "^10.0.0",
43
+ "commander": "^12.0.0",
44
44
  "conode": "^0.1.23",
45
- "glob": "^9.3.0"
45
+ "glob": "^10.3.10"
46
46
  }
47
47
  }