INNER CODE UNIT · TypeScript

geoMean

hasura/graphql-bench · app/queries/src/executors/k6/index.ts:271

function geoMean(xs: number[]): number {
    return xs.map(x => Math.pow(x, 1/xs.length)).reduce((acc, x) => acc * x)
}

// Generate a double histogram of the input numbers: one containing all the
// data, and the other just the first half of the data. Optionally filtering
// out outliers >= maxValue
//
// NOTE: To save space and aid readability we’ll filter out any buckets with a
// count of 0 that follow a bucket with a count of 0. This can still be graphed
// fine without extra accommodations using a stepped line plot, as we plan
function histogram(numBuckets: number, xs: number[], maxValue: number = Number.MAX_SAFE_INTEGER): BasicHistogram {
    if (numBuckets < 1 || xs.length < 2) { throw "We need at least one bucket and xs.length > 1" }
    
    // sort list, keeping track of original index so we can determine which
    // part of the data we're looking at
    var outliersRemoved = 0
    var xsSorted = xs.map((x, ix) => [x,ix])

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…