@tracerbench/stats
Advanced tools
Comparing version 6.1.0 to 6.1.1
@@ -67,4 +67,4 @@ "use strict"; | ||
// set percentage delta from control median | ||
const aMedian = d3_array_1.median(a); | ||
const medianDeltas = d3_array_1.median(deltas); | ||
const aMedian = (0, d3_array_1.median)(a); | ||
const medianDeltas = (0, d3_array_1.median)(deltas); | ||
return { | ||
@@ -78,5 +78,5 @@ min: deltas[lowerU], | ||
asPercent: { | ||
percentMin: utils_1.toNearestHundreth((deltas[lowerU] / aMedian) * 100), | ||
percentMedian: (_a = utils_1.toNearestHundreth((medianDeltas / aMedian) * 100)) !== null && _a !== void 0 ? _a : 0, | ||
percentMax: utils_1.toNearestHundreth((deltas[upperU] / aMedian) * 100) | ||
percentMin: (0, utils_1.toNearestHundreth)((deltas[lowerU] / aMedian) * 100), | ||
percentMedian: (_a = (0, utils_1.toNearestHundreth)((medianDeltas / aMedian) * 100)) !== null && _a !== void 0 ? _a : 0, | ||
percentMax: (0, utils_1.toNearestHundreth)((deltas[upperU] / aMedian) * 100) | ||
} | ||
@@ -83,0 +83,0 @@ }; |
@@ -47,2 +47,9 @@ export interface Bucket { | ||
}; | ||
/** | ||
* Statistics class which powers the TracerBench statistical reporter | ||
* | ||
* | ||
* @param options - IStatsOptions | ||
* @param unitConverterFn - Optional unit converter function which takes a number and returns a number | ||
*/ | ||
export declare class Stats { | ||
@@ -49,0 +56,0 @@ readonly name: string; |
@@ -8,2 +8,9 @@ "use strict"; | ||
const utils_1 = require("./utils"); | ||
/** | ||
* Statistics class which powers the TracerBench statistical reporter | ||
* | ||
* | ||
* @param options - IStatsOptions | ||
* @param unitConverterFn - Optional unit converter function which takes a number and returns a number | ||
*/ | ||
class Stats { | ||
@@ -38,3 +45,3 @@ constructor(options, unitConverterFn) { | ||
this.confidenceInterval = this.getConfidenceInterval(this.controlSorted, this.experimentSorted, confidenceLevel); | ||
this.estimator = utils_1.toNearestHundreth(this.getHodgesLehmann(this.controlSorted, this.experimentSorted)); | ||
this.estimator = (0, utils_1.toNearestHundreth)(this.getHodgesLehmann(this.controlSorted, this.experimentSorted)); | ||
this.sevenFigureSummary = { | ||
@@ -133,11 +140,11 @@ control: this.getSevenFigureSummary(this.controlSorted), | ||
max: Math.round(Math.max.apply(null, a)), | ||
10: Math.round(d3_array_1.quantile(a, 0.1)), | ||
25: Math.round(d3_array_1.quantile(a, 0.25)), | ||
50: Math.round(d3_array_1.quantile(a, 0.5)), | ||
75: Math.round(d3_array_1.quantile(a, 0.75)), | ||
90: Math.round(d3_array_1.quantile(a, 0.9)) | ||
10: Math.round((0, d3_array_1.quantile)(a, 0.1)), | ||
25: Math.round((0, d3_array_1.quantile)(a, 0.25)), | ||
50: Math.round((0, d3_array_1.quantile)(a, 0.5)), | ||
75: Math.round((0, d3_array_1.quantile)(a, 0.75)), | ||
90: Math.round((0, d3_array_1.quantile)(a, 0.9)) | ||
}; | ||
} | ||
getConfidenceInterval(control, experiment, confidenceLevel = 0.95) { | ||
const ci = confidence_interval_1.confidenceInterval(control, experiment, confidenceLevel); | ||
const ci = (0, confidence_interval_1.confidenceInterval)(control, experiment, confidenceLevel); | ||
const isCISig = (ci.min < 0 && 0 < ci.max) || | ||
@@ -148,4 +155,5 @@ (ci.min > 0 && 0 > ci.max) || | ||
: true; | ||
const sigLevel = 1 - confidenceLevel; | ||
// ci sign must match on lower and upper bounds and pValue < 5% | ||
const isSig = isCISig && ci.pValue < 0.05; | ||
const isSig = isCISig && ci.pValue < sigLevel; | ||
return { | ||
@@ -163,4 +171,4 @@ min: Math.round(Math.ceil(ci.min * 100) / 100), | ||
getHodgesLehmann(control, experiment) { | ||
const crossProduct = d3_array_1.cross(control, experiment, (a, b) => a - b).sort((a, b) => a - b); | ||
return d3_array_1.quantile(crossProduct, 0.5); | ||
const crossProduct = (0, d3_array_1.cross)(control, experiment, (a, b) => a - b).sort((a, b) => a - b); | ||
return (0, d3_array_1.quantile)(crossProduct, 0.5); | ||
} | ||
@@ -173,6 +181,6 @@ getRange(control, experiment) { | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
const x = d3_scale_1.scaleLinear() | ||
const x = (0, d3_scale_1.scaleLinear)() | ||
.domain([range.min, range.max]) | ||
.range([range.min, range.max]); | ||
const h = d3_array_1.histogram() | ||
const h = (0, d3_array_1.histogram)() | ||
.value((d) => { | ||
@@ -240,3 +248,3 @@ return d; | ||
getPopulationVariance(a) { | ||
const _mean = d3_array_1.mean(a); | ||
const _mean = (0, d3_array_1.mean)(a); | ||
let sum = 0; | ||
@@ -248,3 +256,3 @@ if (_mean) { | ||
} | ||
return utils_1.toNearestHundreth(sum / a.length); | ||
return (0, utils_1.toNearestHundreth)(sum / a.length); | ||
} | ||
@@ -251,0 +259,0 @@ } |
@@ -0,6 +1,25 @@ | ||
/** | ||
* Convert microseconds to milliseconds | ||
* | ||
* @param ms - Microseconds as either string or number | ||
*/ | ||
export declare function convertMicrosecondsToMS(ms: string | number): number; | ||
/** | ||
* Convert milliseconds to microseconds | ||
* | ||
* @param ms - Milliseconds as either string or number | ||
*/ | ||
export declare function convertMSToMicroseconds(ms: string | number): number; | ||
/** | ||
* Round a float to hundreth decimal place | ||
* | ||
* @param n - Float as a number | ||
*/ | ||
export declare function toNearestHundreth(n: number): number; | ||
/** | ||
* Round a float in microseconds and convert it to milliseconds | ||
* | ||
* @param ms - Microseconds float as a string or number | ||
*/ | ||
export declare function roundFloatAndConvertMicrosecondsToMS(ms: string | number): number; | ||
export declare function fillArray(arrLngth: number, incr?: number, strt?: number): number[]; | ||
//# sourceMappingURL=utils.d.ts.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.fillArray = exports.roundFloatAndConvertMicrosecondsToMS = exports.toNearestHundreth = exports.convertMSToMicroseconds = exports.convertMicrosecondsToMS = void 0; | ||
exports.roundFloatAndConvertMicrosecondsToMS = exports.toNearestHundreth = exports.convertMSToMicroseconds = exports.convertMicrosecondsToMS = void 0; | ||
/** | ||
* Convert microseconds to milliseconds | ||
* | ||
* @param ms - Microseconds as either string or number | ||
*/ | ||
function convertMicrosecondsToMS(ms) { | ||
@@ -9,2 +14,7 @@ ms = typeof ms === 'string' ? parseInt(ms, 10) : ms; | ||
exports.convertMicrosecondsToMS = convertMicrosecondsToMS; | ||
/** | ||
* Convert milliseconds to microseconds | ||
* | ||
* @param ms - Milliseconds as either string or number | ||
*/ | ||
function convertMSToMicroseconds(ms) { | ||
@@ -15,2 +25,7 @@ ms = typeof ms === 'string' ? parseInt(ms, 10) : ms; | ||
exports.convertMSToMicroseconds = convertMSToMicroseconds; | ||
/** | ||
* Round a float to hundreth decimal place | ||
* | ||
* @param n - Float as a number | ||
*/ | ||
function toNearestHundreth(n) { | ||
@@ -20,2 +35,7 @@ return Math.round(n * 100) / 100; | ||
exports.toNearestHundreth = toNearestHundreth; | ||
/** | ||
* Round a float in microseconds and convert it to milliseconds | ||
* | ||
* @param ms - Microseconds float as a string or number | ||
*/ | ||
function roundFloatAndConvertMicrosecondsToMS(ms) { | ||
@@ -27,14 +47,2 @@ ms = typeof ms === 'string' ? parseInt(ms, 10) : ms; | ||
exports.roundFloatAndConvertMicrosecondsToMS = roundFloatAndConvertMicrosecondsToMS; | ||
function fillArray(arrLngth, incr = 1, strt = 0) { | ||
const a = []; | ||
while (a.length < arrLngth) { | ||
if (a.length < 1) { | ||
a.push(strt); | ||
} | ||
a.push(strt + incr); | ||
strt = strt + incr; | ||
} | ||
return a; | ||
} | ||
exports.fillArray = fillArray; | ||
//# sourceMappingURL=utils.js.map |
@@ -13,4 +13,12 @@ export declare const wilcoxonRankSumTable: number[]; | ||
export declare function getSampleUStat(rankSum: number, N: number): number; | ||
/** | ||
* Wilcoxon Rank Sum Test | ||
* independent test of 2 groups tested once | ||
* un-paired two-tailed test alpha 0.05 critical values | ||
* | ||
* @param control - Control as array of numbers | ||
* @param experiment - Experiment as array of numbers | ||
*/ | ||
export declare function getWilcoxonRankSumTest(control: number[], experiment: number[]): boolean; | ||
export {}; | ||
//# sourceMappingURL=wilcoxon-rank-sum.d.ts.map |
@@ -63,4 +63,10 @@ "use strict"; | ||
exports.getSampleUStat = getSampleUStat; | ||
// independent test 2 groups tested once | ||
// un-paired two-tailed test alpha 0.05 critical values | ||
/** | ||
* Wilcoxon Rank Sum Test | ||
* independent test of 2 groups tested once | ||
* un-paired two-tailed test alpha 0.05 critical values | ||
* | ||
* @param control - Control as array of numbers | ||
* @param experiment - Experiment as array of numbers | ||
*/ | ||
function getWilcoxonRankSumTest(control, experiment) { | ||
@@ -67,0 +73,0 @@ const N = control.length; |
@@ -13,4 +13,11 @@ interface ISample { | ||
export declare function getTPlusVal(rankedSamples: ISample[]): number; | ||
/** | ||
* Wilcoxon Signed Rank Test | ||
* paired two-tailed test alpha 0.05 critical values | ||
* | ||
* @param control - Control as array of numbers | ||
* @param listTwo - Experiment as array of numbers | ||
*/ | ||
export declare function getWilcoxonSignedRankTest(control: number[], experiment: number[]): boolean; | ||
export {}; | ||
//# sourceMappingURL=wilcoxon-signed-rank.d.ts.map |
@@ -58,3 +58,9 @@ "use strict"; | ||
exports.getTPlusVal = getTPlusVal; | ||
// paired two-tailed test alpha 0.05 critical values | ||
/** | ||
* Wilcoxon Signed Rank Test | ||
* paired two-tailed test alpha 0.05 critical values | ||
* | ||
* @param control - Control as array of numbers | ||
* @param listTwo - Experiment as array of numbers | ||
*/ | ||
function getWilcoxonSignedRankTest(control, experiment) { | ||
@@ -61,0 +67,0 @@ const N = control.length; |
{ | ||
"name": "@tracerbench/stats", | ||
"version": "6.1.0", | ||
"version": "6.1.1", | ||
"description": "Stats class written in TS-Node", | ||
@@ -24,11 +24,12 @@ "keywords": [ | ||
"scripts": { | ||
"lint": "eslint -c .eslintrc.js --ext .ts .", | ||
"test": "yarn lint && nyc --extension .ts mocha \"test/*.test.ts\"", | ||
"build": "rm -rf ./dist && tsc -b && yarn lint", | ||
"watch": "tsc -b -w", | ||
"prepare": "yarn build" | ||
"lint": "yarn eslint -c .eslintrc.js --ext .ts .", | ||
"test": "yarn lint && yarn nyc --extension .ts mocha \"test/*.test.ts\"", | ||
"build": "rm -rf ./dist && yarn tsc -b && yarn lint", | ||
"watch": "yarn tsc -b -w", | ||
"prepare": "yarn build", | ||
"api-docs": "yarn build && rm -rf ./etc && mkdir ./etc && yarn api-extractor run --local --verbose && yarn api-documenter markdown -i temp" | ||
}, | ||
"dependencies": { | ||
"d3-array": "^2.12.1", | ||
"d3-scale": "^3.3.0", | ||
"d3-array": "2.12.1", | ||
"d3-scale": "3.3.0", | ||
"fs-extra": "^10.0.0", | ||
@@ -38,31 +39,32 @@ "jstat": "^1.9.4", | ||
"tmp": "^0.2.1", | ||
"tslib": "^2.2.0" | ||
"tslib": "^2.3.0" | ||
}, | ||
"devDependencies": { | ||
"@types/chai": "^4.2.17", | ||
"@types/chai": "^4.2.21", | ||
"@types/d3-array": "^2.9.0", | ||
"@types/d3-scale": "^3.2.2", | ||
"@types/fs-extra": "^9.0.11", | ||
"@types/node": "^14.14.19", | ||
"@types/tmp": "^0.2.0", | ||
"@typescript-eslint/eslint-plugin": "^4.22.1", | ||
"@typescript-eslint/parser": "^4.22.1", | ||
"@types/d3-scale": "^4.0.2", | ||
"@types/fs-extra": "^9.0.12", | ||
"@types/node": "^16.3.3", | ||
"@types/tmp": "^0.2.1", | ||
"@typescript-eslint/eslint-plugin": "^4.28.3", | ||
"@typescript-eslint/parser": "^4.28.3", | ||
"chai": "^4.3.4", | ||
"chai-files": "^1.4.0", | ||
"eslint": "^7.25.0", | ||
"eslint": "^7.31.0", | ||
"eslint-config-prettier": "^8.3.0", | ||
"eslint-plugin-filenames": "^1.3.2", | ||
"eslint-plugin-import": "^2.22.1", | ||
"eslint-plugin-import": "^2.23.4", | ||
"eslint-plugin-oclif": "^0.1.0", | ||
"eslint-plugin-prettier": "^3.4.0", | ||
"eslint-plugin-simple-import-sort": "7.0.0", | ||
"mocha": "^8.3.2", | ||
"mock-fs": "^4.14.0", | ||
"mocha": "^9.0.2", | ||
"mock-fs": "^5.0.0", | ||
"nyc": "^15.1.0", | ||
"prettier": "^2.2.1", | ||
"ts-node": "^9.1.1", | ||
"typescript": "^4.2.4", | ||
"typescript-json-schema": "^0.50.0" | ||
"prettier": "^2.3.2", | ||
"ts-node": "^10.1.0", | ||
"typescript": "^4.3.5", | ||
"typescript-json-schema": "^0.50.1" | ||
}, | ||
"engine": "node >= 10" | ||
"engine": "node >= 10", | ||
"gitHead": "50d101586cc9170c51c751d64e5992fd53ca423a" | ||
} |
@@ -6,2 +6,3 @@ ## TracerBench: Automated Chrome Tracing For Benchmarking | ||
## TracerBench | ||
https://www.tracerbench.com/ | ||
@@ -25,4 +26,4 @@ | ||
// sample input (in MS) | ||
const control = [ 1063, 2112, 1154, 988, 1066, 2111, 1097, 1062, 1033, 1017]; | ||
const experiment = [ 1063, 1092, 1088, 1030, 1089, 1047, 959, 1103, 1453, 1034]; | ||
const control = [1063, 2112, 1154, 988, 1066, 2111, 1097, 1062, 1033, 1017]; | ||
const experiment = [1063, 1092, 1088, 1030, 1089, 1047, 959, 1103, 1453, 1034]; | ||
@@ -38,12 +39,12 @@ const stats = new Stats({ | ||
stats.name; // => 'My Experiment'; | ||
stats.controlMS; // => control input converted to ms | ||
stats.experimentMS; // => experiment input converted to ms | ||
stats.controlSortedMS; // => control input sorted + converted to ms | ||
stats.name; // => 'My Experiment'; | ||
stats.controlMS; // => control input converted to ms | ||
stats.experimentMS; // => experiment input converted to ms | ||
stats.controlSortedMS; // => control input sorted + converted to ms | ||
stats.experimentSortedMS; // => experiment input sorted + converted to ms | ||
stats.sampleCount; // => {control: 10, experiment: 10} | ||
stats.range; // => { min: 959, max: 2112 } | ||
stats.sparkLine; // => {control: "█▁▁▁▁▁▁▁▁▁▂", experiment: "█▁▁▁▁▁▁▁▁▁▁"} | ||
stats.sampleCount; // => {control: 10, experiment: 10} | ||
stats.range; // => { min: 959, max: 2112 } | ||
stats.sparkLine; // => {control: "█▁▁▁▁▁▁▁▁▁▂", experiment: "█▁▁▁▁▁▁▁▁▁▁"} | ||
stats.confidenceInterval; // => {min: -46, max: 120, isSig: false} | ||
stats.estimator; // => 9; the median difference between each input pairing (control vs experiment). | ||
stats.estimator; // => 9; the median difference between each input pairing (control vs experiment). | ||
stats.sevenFigureSummary; // => { | ||
@@ -60,2 +61,7 @@ // control: {10: 1014, 25: 1040, 50: 1065, 75: 1140, 90: 2111, min: 988, max: 2112} | ||
# Statistics Primer | ||
https://www.tracerbench.com/docs/guide/stats-primer | ||
# Stats API | ||
https://github.com/TracerBench/tracerbench/blob/master/packages/stats/markdown/stats.md |
@@ -58,2 +58,10 @@ import { cross, histogram, mean, quantile } from 'd3-array'; | ||
}; | ||
/** | ||
* Statistics class which powers the TracerBench statistical reporter | ||
* | ||
* | ||
* @param options - IStatsOptions | ||
* @param unitConverterFn - Optional unit converter function which takes a number and returns a number | ||
*/ | ||
export class Stats { | ||
@@ -300,3 +308,3 @@ public readonly name: string; | ||
experiment: number[], | ||
confidenceLevel: 0.8 | 0.85 | 0.9 | 0.95 | 0.99 | 0.995 | 0.999 = 0.95 | ||
confidenceLevel: IStatsOptions['confidenceLevel'] = 0.95 | ||
): IConfidenceInterval { | ||
@@ -310,4 +318,6 @@ const ci = confidenceInterval(control, experiment, confidenceLevel); | ||
: true; | ||
const sigLevel: number = 1 - confidenceLevel; | ||
// ci sign must match on lower and upper bounds and pValue < 5% | ||
const isSig = isCISig && ci.pValue < 0.05; | ||
const isSig = isCISig && ci.pValue < sigLevel; | ||
return { | ||
@@ -314,0 +324,0 @@ min: Math.round(Math.ceil(ci.min * 100) / 100), |
@@ -0,1 +1,6 @@ | ||
/** | ||
* Convert microseconds to milliseconds | ||
* | ||
* @param ms - Microseconds as either string or number | ||
*/ | ||
export function convertMicrosecondsToMS(ms: string | number): number { | ||
@@ -6,2 +11,7 @@ ms = typeof ms === 'string' ? parseInt(ms, 10) : ms; | ||
/** | ||
* Convert milliseconds to microseconds | ||
* | ||
* @param ms - Milliseconds as either string or number | ||
*/ | ||
export function convertMSToMicroseconds(ms: string | number): number { | ||
@@ -12,2 +22,7 @@ ms = typeof ms === 'string' ? parseInt(ms, 10) : ms; | ||
/** | ||
* Round a float to hundreth decimal place | ||
* | ||
* @param n - Float as a number | ||
*/ | ||
export function toNearestHundreth(n: number): number { | ||
@@ -17,2 +32,7 @@ return Math.round(n * 100) / 100; | ||
/** | ||
* Round a float in microseconds and convert it to milliseconds | ||
* | ||
* @param ms - Microseconds float as a string or number | ||
*/ | ||
export function roundFloatAndConvertMicrosecondsToMS( | ||
@@ -25,13 +45,1 @@ ms: string | number | ||
} | ||
export function fillArray(arrLngth: number, incr = 1, strt = 0): number[] { | ||
const a = []; | ||
while (a.length < arrLngth) { | ||
if (a.length < 1) { | ||
a.push(strt); | ||
} | ||
a.push(strt + incr); | ||
strt = strt + incr; | ||
} | ||
return a; | ||
} |
@@ -70,4 +70,10 @@ // ! we are not using this ATM; rather using the conf interval isSig | ||
// independent test 2 groups tested once | ||
// un-paired two-tailed test alpha 0.05 critical values | ||
/** | ||
* Wilcoxon Rank Sum Test | ||
* independent test of 2 groups tested once | ||
* un-paired two-tailed test alpha 0.05 critical values | ||
* | ||
* @param control - Control as array of numbers | ||
* @param experiment - Experiment as array of numbers | ||
*/ | ||
export function getWilcoxonRankSumTest( | ||
@@ -74,0 +80,0 @@ control: number[], |
@@ -64,3 +64,9 @@ // ! we are not using this ATM; rather using the conf interval isSig | ||
// paired two-tailed test alpha 0.05 critical values | ||
/** | ||
* Wilcoxon Signed Rank Test | ||
* paired two-tailed test alpha 0.05 critical values | ||
* | ||
* @param control - Control as array of numbers | ||
* @param listTwo - Experiment as array of numbers | ||
*/ | ||
export function getWilcoxonSignedRankTest( | ||
@@ -67,0 +73,0 @@ control: number[], |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1517
64
121471
1
Updatedd3-array@2.12.1
Updatedd3-scale@3.3.0
Updatedtslib@^2.3.0