@indutny/bencher 1.1.3 → 1.1.5
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/dist/bin/bencher.js +21 -11
- package/package.json +1 -1
package/dist/bin/bencher.js
CHANGED
|
@@ -27,6 +27,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
27
27
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
28
28
|
};
|
|
29
29
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
30
|
+
const fs_1 = require("fs");
|
|
30
31
|
const promises_1 = require("fs/promises");
|
|
31
32
|
const yargs_1 = __importDefault(require("yargs"));
|
|
32
33
|
const helpers_1 = require("yargs/helpers");
|
|
@@ -35,6 +36,9 @@ const BOLD = 1;
|
|
|
35
36
|
const ITALIC = 3;
|
|
36
37
|
// Go back to previous line, clear the line
|
|
37
38
|
const PREV_LINE = '\x1b[F\x1b[K';
|
|
39
|
+
// From https://github.com/mayuki/Kurukuru
|
|
40
|
+
const SPINNER = ['⠋', '⠙', '⠸', '⠴', '⠦', '⠇'];
|
|
41
|
+
const TICK_FREQUENCY = 1 / 4;
|
|
38
42
|
// t-distribution value for large sample count and p=0.001
|
|
39
43
|
// https://www.itl.nist.gov/div898/handbook/eda/section3/eda3672.htm
|
|
40
44
|
const STUDENT_T = 3.09;
|
|
@@ -100,30 +104,35 @@ async function main() {
|
|
|
100
104
|
for (const m of modules) {
|
|
101
105
|
const paddedName = style(m.name, BOLD) + ':' + ' '.repeat(maxNameLength - m.name.length);
|
|
102
106
|
// Just to reserve the line
|
|
103
|
-
process.stdout.
|
|
107
|
+
(0, fs_1.writeSync)(process.stdout.fd, '\n');
|
|
104
108
|
let ticks = 0;
|
|
105
109
|
const onTick = () => {
|
|
106
|
-
process.stdout.
|
|
107
|
-
ticks =
|
|
110
|
+
(0, fs_1.writeSync)(process.stdout.fd, `${PREV_LINE}${paddedName} ${SPINNER[ticks]}\n`);
|
|
111
|
+
ticks = (ticks + 1) % SPINNER.length;
|
|
108
112
|
};
|
|
109
113
|
onTick();
|
|
110
114
|
const { ops, maxError, usedSamples } = run(m, {
|
|
111
115
|
onTick,
|
|
112
116
|
});
|
|
113
|
-
const stats =
|
|
114
|
-
|
|
117
|
+
const stats = '\x1b[90m' +
|
|
118
|
+
style(`(±${nice(maxError)}, p=${P_VALUE}, n=${usedSamples})`, ITALIC);
|
|
119
|
+
(0, fs_1.writeSync)(process.stdout.fd, `${PREV_LINE}${paddedName} ${nice(ops)} ops/sec ${stats}\n`);
|
|
115
120
|
}
|
|
116
121
|
}
|
|
117
122
|
function run(m, { onTick }) {
|
|
118
|
-
const baseIterations = warmUp(m);
|
|
123
|
+
const { baseIterations, iterationTime } = warmUp(m);
|
|
119
124
|
const samples = new Array();
|
|
120
|
-
const tickEvery =
|
|
125
|
+
const tickEvery = TICK_FREQUENCY / iterationTime;
|
|
126
|
+
let totalIterations = 0;
|
|
127
|
+
let nextTick = tickEvery;
|
|
121
128
|
for (let i = 0; i < m.options.samples; i++) {
|
|
122
129
|
const iterations = baseIterations * (1 + (i % m.options.sweepWidth));
|
|
123
130
|
const duration = measure(m, iterations);
|
|
124
131
|
samples.push({ duration, iterations });
|
|
125
|
-
|
|
132
|
+
totalIterations += iterations;
|
|
133
|
+
while (totalIterations > nextTick) {
|
|
126
134
|
onTick();
|
|
135
|
+
nextTick += tickEvery;
|
|
127
136
|
}
|
|
128
137
|
}
|
|
129
138
|
const { beta, confidence, outliers } = regress(m, samples);
|
|
@@ -156,8 +165,9 @@ function warmUp(m) {
|
|
|
156
165
|
iterations *= 2;
|
|
157
166
|
duration = measure(m, Math.round(iterations));
|
|
158
167
|
} while (duration < maxSampleDuration);
|
|
159
|
-
|
|
160
|
-
|
|
168
|
+
const iterationTime = duration / Math.round(iterations);
|
|
169
|
+
iterations = Math.round(Math.max(iterations / 2, (maxSampleDuration / duration) * iterations));
|
|
170
|
+
return { baseIterations: iterations, iterationTime };
|
|
161
171
|
}
|
|
162
172
|
function measure(m, iterations) {
|
|
163
173
|
let sum = 0;
|
|
@@ -238,7 +248,7 @@ function style(text, code) {
|
|
|
238
248
|
function nice(n) {
|
|
239
249
|
let result = n.toFixed(1);
|
|
240
250
|
for (let i = result.length - 5; i > 0; i -= 3) {
|
|
241
|
-
result = result.slice(0, i) +
|
|
251
|
+
result = result.slice(0, i) + '’' + result.slice(i);
|
|
242
252
|
}
|
|
243
253
|
return result;
|
|
244
254
|
}
|