@indutny/bencher 1.1.2 → 1.1.3

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.
@@ -98,22 +98,33 @@ async function main() {
98
98
  }));
99
99
  const maxNameLength = modules.reduce((len, { name }) => Math.max(len, name.length), 0);
100
100
  for (const m of modules) {
101
- const paddedName = m.name + ' '.repeat(maxNameLength - m.name.length);
102
- process.stdout.write(`${style(paddedName, BOLD)}: running...\n`);
103
- const { ops, maxError, usedSamples } = run(m);
104
- process.stdout.write(PREV_LINE);
105
- process.stdout.write(`${style(paddedName, BOLD)}: ${ops.toFixed(1)} ops/s ` +
106
- style(`(±${maxError.toFixed(1)}, p=${P_VALUE}, n=${usedSamples})`, ITALIC) +
107
- '\n');
101
+ const paddedName = style(m.name, BOLD) + ':' + ' '.repeat(maxNameLength - m.name.length);
102
+ // Just to reserve the line
103
+ process.stdout.write('\n');
104
+ let ticks = 0;
105
+ const onTick = () => {
106
+ process.stdout.write(`${PREV_LINE}${paddedName} ${'.'.repeat(ticks)}\n`);
107
+ ticks = 1 + (ticks % 3);
108
+ };
109
+ onTick();
110
+ const { ops, maxError, usedSamples } = run(m, {
111
+ onTick,
112
+ });
113
+ const stats = style(`(±${nice(maxError)}, p=${P_VALUE}, n=${usedSamples})`, ITALIC);
114
+ process.stdout.write(`${PREV_LINE}${paddedName} ${nice(ops)} ops/sec ${stats}\n`);
108
115
  }
109
116
  }
110
- function run(m) {
117
+ function run(m, { onTick }) {
111
118
  const baseIterations = warmUp(m);
112
119
  const samples = new Array();
120
+ const tickEvery = Math.round(m.options.samples / m.options.duration);
113
121
  for (let i = 0; i < m.options.samples; i++) {
114
122
  const iterations = baseIterations * (1 + (i % m.options.sweepWidth));
115
123
  const duration = measure(m, iterations);
116
124
  samples.push({ duration, iterations });
125
+ if (i % tickEvery === 0) {
126
+ onTick();
127
+ }
117
128
  }
118
129
  const { beta, confidence, outliers } = regress(m, samples);
119
130
  const ops = 1 / beta;
@@ -224,6 +235,13 @@ function regress(m, samples) {
224
235
  function style(text, code) {
225
236
  return `\x1b[${code}m${text}\x1b[m`;
226
237
  }
238
+ function nice(n) {
239
+ let result = n.toFixed(1);
240
+ for (let i = result.length - 5; i > 0; i -= 3) {
241
+ result = result.slice(0, i) + "'" + result.slice(i);
242
+ }
243
+ return result;
244
+ }
227
245
  main().catch((err) => {
228
246
  console.error(err);
229
247
  process.exit(1);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@indutny/bencher",
3
- "version": "1.1.2",
3
+ "version": "1.1.3",
4
4
  "description": "Simple benchmarking tool",
5
5
  "bin": {
6
6
  "bencher": "./dist/bin/bencher.js"