silverwolf-x's picture
download
raw
1.03 kB
/**
* Shared statistics utilities for benchmark measurements
*/
/**
* Calculate statistical summary for an array of numbers
* @param {number[]} arr - Array of numeric values
* @returns {Object|null} Stats object with median, min, max, mean, stddev, cv or null if empty
*/
function calcStats(arr) {
if (arr.length === 0) return null
const sorted = [...arr].sort((a, b) => a - b)
const mid = Math.floor(sorted.length / 2)
const median =
sorted.length % 2 ? sorted[mid] : (sorted[mid - 1] + sorted[mid]) / 2
const min = sorted[0]
const max = sorted[sorted.length - 1]
const mean = arr.reduce((a, b) => a + b, 0) / arr.length
const variance =
arr.reduce((sum, val) => sum + Math.pow(val - mean, 2), 0) / arr.length
const stddev = Math.sqrt(variance)
const cv = mean > 0 ? (stddev / mean) * 100 : 0 // coefficient of variation as %
return {
median,
min,
max,
mean: Math.round(mean),
stddev: Math.round(stddev),
cv: Math.round(cv),
}
}
module.exports = { calcStats }

Xet Storage Details

Size:
1.03 kB
·
Xet hash:
ac419f8595b382747932e1b1811b323ce81725a85f19e352b2859c3d5ad15516

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.