INNER CODE UNIT · TypeScript

histogram

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

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])
                     .filter(([x,_]) => { 
                         let ok = x < maxValue
                         if (!ok) outliersRemoved++
                         return ok
                     })
    xsSorted.sort((a,b) => a[0] - b[0])
    // index of last element in the first half of data:
    const ix1stHalfLast = xs.length/2 - 1
    
    const bucketWidth = (xsSorted[xsSorted.length - 1][0] - xsSorted[0][0]) / numBuckets
     

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…