@indutny/bencher 1.1.3 → 1.1.4

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.
@@ -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,8 @@ 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
+ const SPINNER = ['⠋', '⠙', '⠸', '⠴', '⠦', '⠇'];
40
+ const TICK_FREQUENCY = 1 / 4;
38
41
  // t-distribution value for large sample count and p=0.001
39
42
  // https://www.itl.nist.gov/div898/handbook/eda/section3/eda3672.htm
40
43
  const STUDENT_T = 3.09;
@@ -100,30 +103,34 @@ async function main() {
100
103
  for (const m of modules) {
101
104
  const paddedName = style(m.name, BOLD) + ':' + ' '.repeat(maxNameLength - m.name.length);
102
105
  // Just to reserve the line
103
- process.stdout.write('\n');
106
+ (0, fs_1.writeSync)(process.stdout.fd, '\n');
104
107
  let ticks = 0;
105
108
  const onTick = () => {
106
- process.stdout.write(`${PREV_LINE}${paddedName} ${'.'.repeat(ticks)}\n`);
107
- ticks = 1 + (ticks % 3);
109
+ (0, fs_1.writeSync)(process.stdout.fd, `${PREV_LINE}${paddedName} ${SPINNER[ticks]}\n`);
110
+ ticks = (ticks + 1) % SPINNER.length;
108
111
  };
109
112
  onTick();
110
113
  const { ops, maxError, usedSamples } = run(m, {
111
114
  onTick,
112
115
  });
113
116
  const stats = style(`(±${nice(maxError)}, p=${P_VALUE}, n=${usedSamples})`, ITALIC);
114
- process.stdout.write(`${PREV_LINE}${paddedName} ${nice(ops)} ops/sec ${stats}\n`);
117
+ (0, fs_1.writeSync)(process.stdout.fd, `${PREV_LINE}${paddedName} ${nice(ops)} ops/sec ${stats}\n`);
115
118
  }
116
119
  }
117
120
  function run(m, { onTick }) {
118
- const baseIterations = warmUp(m);
121
+ const { baseIterations, iterationTime } = warmUp(m);
119
122
  const samples = new Array();
120
- const tickEvery = Math.round(m.options.samples / m.options.duration);
123
+ const tickEvery = TICK_FREQUENCY / iterationTime;
124
+ let totalIterations = 0;
125
+ let nextTick = tickEvery;
121
126
  for (let i = 0; i < m.options.samples; i++) {
122
127
  const iterations = baseIterations * (1 + (i % m.options.sweepWidth));
123
128
  const duration = measure(m, iterations);
124
129
  samples.push({ duration, iterations });
125
- if (i % tickEvery === 0) {
130
+ totalIterations += iterations;
131
+ while (totalIterations > nextTick) {
126
132
  onTick();
133
+ nextTick += tickEvery;
127
134
  }
128
135
  }
129
136
  const { beta, confidence, outliers } = regress(m, samples);
@@ -156,8 +163,9 @@ function warmUp(m) {
156
163
  iterations *= 2;
157
164
  duration = measure(m, Math.round(iterations));
158
165
  } while (duration < maxSampleDuration);
159
- iterations = Math.max(iterations / 2, (maxSampleDuration / duration) * iterations);
160
- return iterations;
166
+ const iterationTime = duration / Math.round(iterations);
167
+ iterations = Math.round(Math.max(iterations / 2, (maxSampleDuration / duration) * iterations));
168
+ return { baseIterations: iterations, iterationTime };
161
169
  }
162
170
  function measure(m, iterations) {
163
171
  let sum = 0;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@indutny/bencher",
3
- "version": "1.1.3",
3
+ "version": "1.1.4",
4
4
  "description": "Simple benchmarking tool",
5
5
  "bin": {
6
6
  "bencher": "./dist/bin/bencher.js"