tscircuit/autorouting-dataset-01

This code manages the hardware and electronic components for circuit design and PCB layout, defining components like resistors, capacitors, transistors, connectors, and footprints, and providing tools for component placement, PCB topology, and electrical connections.

Version
1.0.102
License
unset
Stars
4

scripts/run-benchmark/getPercentileMs.ts

/**
 * Return percentile for a list of durations in milliseconds.
 */
export const getPercentileMs = (
  durationMsList: number[],
  percentile: number,
): number | null => {
  if (durationMsList.length === 0) {
    return null
  }
  const sorted = [...durationMsList].sort((a, b) => a - b)
  const clampedPercentile = Math.min(Math.max(percentile, 0), 1)
  const position = (sorted.length - 1) * clampedPercentile
  const lowerIndex = Math.floor(position)
  const upperIndex = Math.ceil(position)
  const lowerValue = sorted[lowerIndex]
  const upperValue = sorted[upperIndex]
  if (lowerIndex === upperIndex) {
    return lowerValue
  }
  const weight = position - lowerIndex
  return lowerValue + (upperValue - lowerValue) * weight
}