@indutny/bencher 1.2.0 → 2.0.0
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 +2 -5
- package/dist/bin/bencher.js +14 -8
- package/package.json +9 -9
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
|
|
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
|
-
|
|
43
|
+
benchmark.js/benchmarkName: 1’037.8 ops/sec (±18.8, p=0.001, n=98)
|
|
47
44
|
```
|
|
48
45
|
|
|
49
46
|
## LICENSE
|
package/dist/bin/bencher.js
CHANGED
|
@@ -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,8 +97,14 @@ async function main() {
|
|
|
97
97
|
if (warmUpDuration <= 0) {
|
|
98
98
|
throw new Error(`${file}: options.warmUpDuration must be positive`);
|
|
99
99
|
}
|
|
100
|
-
|
|
101
|
-
|
|
100
|
+
const functions = new Array();
|
|
101
|
+
for (const key of Object.keys(m)) {
|
|
102
|
+
if (typeof m[key] === 'function') {
|
|
103
|
+
functions.push(m[key]);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
return functions.map((fn) => ({
|
|
107
|
+
name: `${file}/${fn.name}`,
|
|
102
108
|
options: {
|
|
103
109
|
duration,
|
|
104
110
|
sweepWidth,
|
|
@@ -106,9 +112,9 @@ async function main() {
|
|
|
106
112
|
warmUpDuration,
|
|
107
113
|
ignoreOutliers,
|
|
108
114
|
},
|
|
109
|
-
|
|
110
|
-
};
|
|
111
|
-
}));
|
|
115
|
+
fn,
|
|
116
|
+
}));
|
|
117
|
+
}))).flat();
|
|
112
118
|
const maxNameLength = modules.reduce((len, { name }) => Math.max(len, name.length), 0);
|
|
113
119
|
for (const m of modules) {
|
|
114
120
|
const paddedName = BOLD + m.name + RESET + ':' + ' '.repeat(maxNameLength - m.name.length);
|
|
@@ -169,7 +175,7 @@ function warmUp(m) {
|
|
|
169
175
|
const coldDuration = measure(m, 1);
|
|
170
176
|
const warmUpIterations = m.options.warmUpDuration / coldDuration;
|
|
171
177
|
for (let i = 0; i < warmUpIterations; i++) {
|
|
172
|
-
m.
|
|
178
|
+
m.fn();
|
|
173
179
|
}
|
|
174
180
|
// Compute max duration per base sample
|
|
175
181
|
let sampleMultiplier = 0;
|
|
@@ -192,7 +198,7 @@ function measure(m, iterations) {
|
|
|
192
198
|
let sum = 0;
|
|
193
199
|
const start = process.hrtime.bigint();
|
|
194
200
|
for (let i = 0; i < iterations; i++) {
|
|
195
|
-
sum += m.
|
|
201
|
+
sum += m.fn();
|
|
196
202
|
}
|
|
197
203
|
const duration = Number(process.hrtime.bigint() - start) / 1e9;
|
|
198
204
|
if (isNaN(sum)) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@indutny/bencher",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "Simple benchmarking tool",
|
|
5
5
|
"bin": {
|
|
6
6
|
"bencher": "./dist/bin/bencher.js"
|
|
@@ -9,13 +9,6 @@
|
|
|
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",
|
|
@@ -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
|
+
}
|