@indutny/bencher 1.2.0 → 2.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/README.md CHANGED
@@ -24,11 +24,8 @@ npm install -g @indutny/bencher
24
24
  ## Usage
25
25
 
26
26
  ```js
27
- // benchmark.js
28
- export const name = 'runner';
29
-
30
27
  // Function to benchmark
31
- export default () => {
28
+ export function benchmarkName() => {
32
29
  let sum = 0;
33
30
  for (let i = 0; i < 1e6; i++) {
34
31
  sum += i;
@@ -43,7 +40,7 @@ export default () => {
43
40
 
44
41
  ```sh
45
42
  $ bencher benchmark.js
46
- runner: 1’037.8 ops/sec (±18.8, p=0.001, n=98)
43
+ benchmark.js/benchmarkName: 1’037.8 ops/sec (±18.8, p=0.001, n=98)
47
44
  ```
48
45
 
49
46
  ## LICENSE
@@ -77,7 +77,7 @@ async function main() {
77
77
  type: 'boolean',
78
78
  describe: "don't report severe outliers",
79
79
  }).argv;
80
- const modules = await Promise.all(argv._.map(async (file) => {
80
+ const modules = (await Promise.all(argv._.map(async (file) => {
81
81
  var _a;
82
82
  const path = await (0, promises_1.realpath)(String(file));
83
83
  const m = await (_a = path, Promise.resolve().then(() => __importStar(require(_a))));
@@ -97,21 +97,41 @@ async function main() {
97
97
  if (warmUpDuration <= 0) {
98
98
  throw new Error(`${file}: options.warmUpDuration must be positive`);
99
99
  }
100
- return {
101
- name: m.name ?? String(file),
102
- options: {
103
- duration,
104
- sweepWidth,
105
- samples,
106
- warmUpDuration,
107
- ignoreOutliers,
108
- },
109
- default: m.default,
100
+ const options = {
101
+ duration,
102
+ sweepWidth,
103
+ samples,
104
+ warmUpDuration,
105
+ ignoreOutliers,
110
106
  };
111
- }));
112
- const maxNameLength = modules.reduce((len, { name }) => Math.max(len, name.length), 0);
107
+ const result = new Array();
108
+ for (const key of Object.keys(m)) {
109
+ if (typeof m[key] === 'function') {
110
+ result.push({
111
+ file: String(file),
112
+ name: key,
113
+ fn: m[key],
114
+ options,
115
+ });
116
+ }
117
+ }
118
+ return result;
119
+ }))).flat();
120
+ modules.sort((a, b) => {
121
+ if (a.name === b.name) {
122
+ return a.file < b.file ? -1 : 1;
123
+ }
124
+ return a.name < b.name ? -1 : 1;
125
+ });
126
+ const maxNameLength = modules.reduce((len, { file, name }) => Math.max(len, file.length + name.length), 0);
113
127
  for (const m of modules) {
114
- const paddedName = BOLD + m.name + RESET + ':' + ' '.repeat(maxNameLength - m.name.length);
128
+ const paddedName = BOLD +
129
+ m.file +
130
+ '/' +
131
+ m.name +
132
+ RESET +
133
+ ':' +
134
+ ' '.repeat(maxNameLength - m.name.length - m.file.length);
115
135
  // Just to reserve the line
116
136
  (0, fs_1.writeSync)(process.stdout.fd, '\n');
117
137
  let ticks = 0;
@@ -169,7 +189,7 @@ function warmUp(m) {
169
189
  const coldDuration = measure(m, 1);
170
190
  const warmUpIterations = m.options.warmUpDuration / coldDuration;
171
191
  for (let i = 0; i < warmUpIterations; i++) {
172
- m.default();
192
+ m.fn();
173
193
  }
174
194
  // Compute max duration per base sample
175
195
  let sampleMultiplier = 0;
@@ -192,7 +212,7 @@ function measure(m, iterations) {
192
212
  let sum = 0;
193
213
  const start = process.hrtime.bigint();
194
214
  for (let i = 0; i < iterations; i++) {
195
- sum += m.default();
215
+ sum += m.fn();
196
216
  }
197
217
  const duration = Number(process.hrtime.bigint() - start) / 1e9;
198
218
  if (isNaN(sum)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@indutny/bencher",
3
- "version": "1.2.0",
3
+ "version": "2.1.1",
4
4
  "description": "Simple benchmarking tool",
5
5
  "bin": {
6
6
  "bencher": "./dist/bin/bencher.js"
@@ -9,28 +9,21 @@
9
9
  "dist/bin/*.js",
10
10
  "README.md"
11
11
  ],
12
- "scripts": {
13
- "build": "tsc",
14
- "lint": "eslint --cache .",
15
- "format": "prettier --cache --write .",
16
- "check:format": "prettier --cache --check .",
17
- "prepublish": "rm -rf dist && npm run build"
18
- },
19
12
  "keywords": [
20
13
  "benchmark",
21
14
  "sweep",
22
15
  "regression"
23
16
  ],
24
- "author": "Fedor Indutny <238531+indutny@users.noreply.github.com>",
17
+ "author": "Fedor Indutny <indutny@reply.codeberg.org>",
25
18
  "license": "MIT",
26
19
  "repository": {
27
20
  "type": "git",
28
- "url": "git+https://github.com/indutny/bencher.git"
21
+ "url": "git+https://codeberg.org/indutny/bencher.git"
29
22
  },
30
23
  "bugs": {
31
- "url": "https://github.com/indutny/bencher/issues"
24
+ "url": "https://codeberg.org/indutny/bencher/issues"
32
25
  },
33
- "homepage": "https://github.com/indutny/bencher#readme",
26
+ "homepage": "https://codeberg.org/indutny/bencher#readme",
34
27
  "devDependencies": {
35
28
  "@types/yargs": "^17.0.17",
36
29
  "@typescript-eslint/eslint-plugin": "^5.47.0",
@@ -42,5 +35,12 @@
42
35
  },
43
36
  "dependencies": {
44
37
  "yargs": "^17.6.2"
38
+ },
39
+ "scripts": {
40
+ "build": "tsc",
41
+ "lint": "eslint --cache .",
42
+ "format": "prettier --cache --write .",
43
+ "check:format": "prettier --cache --check .",
44
+ "prepublish": "rm -rf dist && npm run build"
45
45
  }
46
- }
46
+ }