@indutny/bencher
Advanced tools
Comparing version 1.1.1 to 1.1.2
@@ -33,2 +33,11 @@ #!/usr/bin/env node | ||
const helpers_1 = require("yargs/helpers"); | ||
// ANSI colors | ||
const BOLD = 1; | ||
const ITALIC = 3; | ||
// Go back to previous line, clear the line | ||
const PREV_LINE = '\x1b[F\x1b[K'; | ||
// t-distribution value for large sample count and p=0.001 | ||
// https://www.itl.nist.gov/div898/handbook/eda/section3/eda3672.htm | ||
const STUDENT_T = 3.09; | ||
const P_VALUE = 0.001; | ||
async function main() { | ||
@@ -91,4 +100,11 @@ const argv = await (0, yargs_1.default)((0, helpers_1.hideBin)(process.argv)) | ||
})); | ||
const maxNameLength = modules.reduce((len, { name }) => Math.max(len, name.length), 0); | ||
for (const m of modules) { | ||
run(m); | ||
const paddedName = m.name + ' '.repeat(maxNameLength - m.name.length); | ||
process.stdout.write(`${style(paddedName, BOLD)}: running...\n`); | ||
const { ops, maxError, usedSamples } = run(m); | ||
process.stdout.write(PREV_LINE); | ||
process.stdout.write(`${style(paddedName, BOLD)}: ${ops.toFixed(1)} ops/s ` + | ||
style(`(±${maxError.toFixed(1)}, p=${P_VALUE}, n=${usedSamples})`, ITALIC) + | ||
'\n'); | ||
} | ||
@@ -104,10 +120,13 @@ } | ||
} | ||
const { beta, c95, outliers } = regress(m, samples); | ||
const { beta, confidence, outliers } = regress(m, samples); | ||
const ops = 1 / beta; | ||
const lowOps = 1 / (beta + c95); | ||
const highOps = 1 / (beta - c95); | ||
const lowOps = 1 / (beta + confidence); | ||
const highOps = 1 / (beta - confidence); | ||
const maxError = Math.max(highOps - ops, ops - lowOps); | ||
const usedSamples = samples.length - outliers; | ||
console.log(`${m.name}: ${ops.toFixed(1)} ops/s ` + | ||
`(±${maxError.toFixed(1)}, p=0.05, n=${usedSamples})`); | ||
return { | ||
ops, | ||
maxError, | ||
usedSamples, | ||
}; | ||
} | ||
@@ -201,11 +220,12 @@ function warmUp(m) { | ||
stdError = Math.sqrt(stdError); | ||
// t-distribution value for large sample count and p=0.05 | ||
const T_VALUE = 1.9719; | ||
return { | ||
alpha, | ||
beta, | ||
c95: T_VALUE * stdError, | ||
confidence: STUDENT_T * stdError, | ||
outliers: samples.length - withoutOutliers.length, | ||
}; | ||
} | ||
function style(text, code) { | ||
return `\x1b[${code}m${text}\x1b[m`; | ||
} | ||
main().catch((err) => { | ||
@@ -212,0 +232,0 @@ console.error(err); |
{ | ||
"name": "@indutny/bencher", | ||
"version": "1.1.1", | ||
"version": "1.1.2", | ||
"description": "Simple benchmarking tool", | ||
@@ -5,0 +5,0 @@ "bin": { |
11871
230