Skip to content

Commit

Permalink
Renaming
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky committed Jan 9, 2022
1 parent 75c045b commit 73f460d
Show file tree
Hide file tree
Showing 12 changed files with 50 additions and 57 deletions.
2 changes: 1 addition & 1 deletion src/combination/tasks/find.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const findTasks = async function ({
const [{ taskIds: ids }] = await measureCombinations(
[{ dimensions: { runner }, taskPath, inputsList: [] }],
{
precisionTarget: 0,
precision: 0,
cwd,
previewState: { quiet: true },
outliers: true,
Expand Down
2 changes: 1 addition & 1 deletion src/dev/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const combinationDev = async function (combination, noDimensions, { cwd }) {
printCombinationName(combination, noDimensions)

await measureCombinations([combination], {
precisionTarget: 0,
precision: 0,
cwd,
previewState: { quiet: true },
outliers: true,
Expand Down
4 changes: 2 additions & 2 deletions src/run/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ const previewAndMeasure = async function ({
noDimensions,
previewState,
config,
config: { cwd, precisionTarget, outliers },
config: { cwd, precision, outliers },
}) {
const previewStateA = await startPreview({
newResult,
Expand All @@ -68,7 +68,7 @@ const previewAndMeasure = async function ({

try {
const combinations = await measureCombinations(newResult.combinations, {
precisionTarget,
precision,
cwd,
previewState: previewStateA,
outliers,
Expand Down
13 changes: 6 additions & 7 deletions src/run/measure/loop.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import { isRemainingCombination } from './remaining.js'
// In that case, the task complexity should be increased, for example by using
// bigger `inputs`.
export const performMeasureLoop = async function ({
precisionTarget,
precision,
previewState,
stopState,
stage,
Expand All @@ -39,12 +39,11 @@ export const performMeasureLoop = async function ({
startStat,
}) {
const { stats } = await pWhile(
(state) =>
isRemainingCombination(state, { precisionTarget, stage, stopState }),
(state) => isRemainingCombination(state, { precision, stage, stopState }),
(state) =>
performSample(state, {
previewState,
precisionTarget,
precision,
outliers,
server,
minLoopDuration,
Expand All @@ -67,7 +66,7 @@ const performSample = async function (
{ sampleState, stats, durationState },
{
previewState,
precisionTarget,
precision,
outliers,
server,
minLoopDuration,
Expand All @@ -87,7 +86,7 @@ const performSample = async function (
sampleState: sampleStateA,
minLoopDuration,
outliers,
precisionTarget,
precision,
})
const statsB = endRunDuration(startStat, statsA)
await Promise.all([
Expand All @@ -96,7 +95,7 @@ const performSample = async function (
previewState,
durationState,
sampleState: sampleStateB,
precisionTarget,
precision,
}),
truncateLogs(logsFd),
])
Expand Down
10 changes: 5 additions & 5 deletions src/run/measure/remaining.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { hasMaxMeasures } from '../sample/max_measures.js'
// means a benchmark might succeed or not depending on the machine.
export const isRemainingCombination = function (
{ sampleState: { allSamples, measures }, stats: { loops, rmoe, cold } },
{ precisionTarget, stage, stopState: { stopped } },
{ precision, stage, stopState: { stopped } },
) {
if (stopped) {
return false
Expand All @@ -29,23 +29,23 @@ export const isRemainingCombination = function (
return allSamples === 0
}

return shouldKeepRunning({ measures, loops, rmoe, cold, precisionTarget })
return shouldKeepRunning({ measures, loops, rmoe, cold, precision })
}

const shouldKeepRunning = function ({
measures,
loops,
rmoe,
cold,
precisionTarget,
precision,
}) {
if (hasMaxMeasures(measures)) {
return false
}

if (precisionTarget === 0) {
if (precision === 0) {
return loops === 0
}

return !isPreciseEnough(rmoe, cold, precisionTarget)
return !isPreciseEnough(rmoe, cold, precision)
}
18 changes: 9 additions & 9 deletions src/run/precision.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { UserError } from '../error/main.js'

// Replaces `precision` configuration property by `precisionTarget`.
// Normalize `precision` configuration property value.
// Also validates it.
// For each of those `precision` values, each combination stops once its `rmoe`
// reached the corresponding `precisionTarget`.
// For each of those `precision` original value, each combination stops once
// its `rmoe` reached the corresponding `precision` normalized value.
// There are several advantages in using `precision` instead of a `duration`:
// - A `duration` makes the precision (`rmoe`) machine-dependent or
// hardward load-dependent
Expand Down Expand Up @@ -79,15 +79,15 @@ export const normalizePrecision = function (precision, name) {
throw new UserError(`'${name}' must be a positive integer: ${precision}`)
}

const precisionTarget = PRECISION_TARGETS[precision]
const precisionA = PRECISION_TARGETS[precision]

if (precisionTarget === undefined) {
if (precisionA === undefined) {
throw new UserError(
`'${name}' must be between ${MIN_PRECISION} and ${MAX_PRECISION}, not ${precision}`,
)
}

return { precisionTarget }
return { precision: precisionA }
}

// Associates `precision` (using array index) to the minimum `rmoe` each
Expand Down Expand Up @@ -120,11 +120,11 @@ const MAX_PRECISION = PRECISION_TARGETS.length - 1
// - This also means those are never reported if `precision: 0`
// We also check that performance optimization has ended
// - We compare `cold` to the same threshold to do so.
export const isPreciseEnough = function (rmoe, cold, precisionTarget) {
export const isPreciseEnough = function (rmoe, cold, precision) {
return (
rmoe !== undefined &&
rmoe <= precisionTarget &&
rmoe <= precision &&
cold !== undefined &&
cold <= precisionTarget
cold <= precision
)
}
8 changes: 4 additions & 4 deletions src/run/preview/results/duration.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ export const updateCombinationEnd = function ({
previewState: { previewSamples, combinationEnd: previousCombinationEnd },
durationState: { sampleDurationMean },
sampleState: { coldLoopsTarget },
precisionTarget,
precision,
}) {
if (sampleDurationMean === undefined || stdev === undefined || stdev === 0) {
return
}

const samplesLeft = getSamplesLeft(stats, precisionTarget, coldLoopsTarget)
const samplesLeft = getSamplesLeft(stats, precision, coldLoopsTarget)
const combinationEnd = getCombinationEnd(samplesLeft, sampleDurationMean)
const combinationEndA = smoothCombinationEnd({
combinationEnd,
Expand All @@ -44,15 +44,15 @@ export const updateCombinationEnd = function ({
// `precision`.
const getSamplesLeft = function (
{ samples, loops, mean, stdev, min, max, outliersMin, outliersMax },
precisionTarget,
precision,
coldLoopsTarget,
) {
const moeLengthTarget = getLengthForMoe({
mean,
stdev,
min,
max,
precisionTarget,
precision,
})
const moeLoopsTarget = getLoopsFromLength(
moeLengthTarget,
Expand Down
4 changes: 2 additions & 2 deletions src/run/preview/results/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const updatePreviewStats = async function ({
previewState,
durationState,
sampleState,
precisionTarget,
precision,
}) {
if (shouldSkipPreview(previewState, stats)) {
return
Expand All @@ -37,7 +37,7 @@ export const updatePreviewStats = async function ({
previewState,
durationState,
sampleState,
precisionTarget,
precision,
})
setDescriptionIf(previewState, MEASURE_DESCRIPTION, START_DESCRIPTION)

Expand Down
4 changes: 2 additions & 2 deletions src/stats/add.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export const addStats = function ({
sampleState: { measures, unsortedMeasures, sampleLoops, sampleTimes },
minLoopDuration,
outliers,
precisionTarget,
precision,
}) {
if (measures.length === 0) {
return { stats, sampleState }
Expand All @@ -64,7 +64,7 @@ export const addStats = function ({
measures,
unsortedMeasures,
outliers,
precisionTarget,
precision,
})
return {
stats: { ...countStats, ...computedStats },
Expand Down
12 changes: 6 additions & 6 deletions src/stats/cold/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ import { findClosestMean, findHotIndex } from './find.js'
export const getColdStats = function (
array,
{
precisionTarget,
precision,
mean = getMean(array),
filter = defaultFilter,
length = array.filter(filter).length,
},
) {
const cold = getCold(array, { mean, filter, length })
const coldLoopsTarget = getColdLoopsTarget(array, {
precisionTarget,
precision,
mean,
filter,
length,
Expand Down Expand Up @@ -60,7 +60,7 @@ const getCold = function (array, { mean, filter, length }) {
return cold
}

// Approximate the number of loops left for `cold` to be below `precisionTarget`
// Approximate the number of loops left for `cold` to be below `precision`.
// Used to estimate the duration of the benchmark in previews.
// This is based on the assumption that:
// - The total mean is stable
Expand All @@ -85,11 +85,11 @@ const getCold = function (array, { mean, filter, length }) {
// - Most of the time, the `moeLoopsTarget` is larger than `coldLoopsTarget`
const getColdLoopsTarget = function (
array,
{ precisionTarget, mean, filter, length },
{ precision, mean, filter, length },
) {
const minIndex = getIndexFromLength(COLD_MIN_PERCENTAGE, length)
const incrementalMeanMin = mean * (1 - precisionTarget)
const incrementalMeanMax = mean * (1 + precisionTarget)
const incrementalMeanMin = mean * (1 - precision)
const incrementalMeanMax = mean * (1 + precision)
const hotIndex = findHotIndex(array, {
minIndex,
filter,
Expand Down
4 changes: 2 additions & 2 deletions src/stats/compute.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export const computeStats = function ({
measures,
unsortedMeasures,
outliers,
precisionTarget,
precision,
}) {
const { outliersMin, outliersMax } = getOutliersPercentage(measures, outliers)
const { minIndex, maxIndex, length } = getLengthFromLoops(
Expand All @@ -75,7 +75,7 @@ export const computeStats = function ({
)
const mean = getMean(measures, { minIndex, maxIndex })
const { cold, coldLoopsTarget } = getColdStats(unsortedMeasures, {
precisionTarget,
precision,
mean,
filter,
length,
Expand Down
26 changes: 10 additions & 16 deletions src/stats/moe.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export const getMoe = function (stdev, length) {

// Retrieve margin of error relative to the mean.
// This is more useful than moe when comparing different combinations, or when
// targetting a specific `precisionTarget`.
// targetting a specific `precision`.
// Confidence interval:
// - Unlike `moe`, `rmoe` can be impacted by the mean's inaccuracy (due to
// being estimated)
Expand All @@ -99,8 +99,8 @@ export const getMoe = function (stdev, length) {
// - The difference with `rmoe` is:
// - Too low to be worth the added complexity
// - Constant for a given `precision`, i.e. could be considered part of
// the `precisionTarget` itself
// - e.g. 10% `precisionTarget` is actually always `[9.1%, 11.1%]`
// the `precision` itself
// - e.g. 10% `precision` is actually always `[9.1%, 11.1%]`
// - It is not a problem even when mean inaccuracy is high
// - Because that is only likely when rstdev is high and sample size low
// - Which is proportional to a higher `moe|rmoe`
Expand All @@ -113,16 +113,10 @@ export const getRmoe = function (moe, mean) {
// Since `length` is used in non-straight-forward ways (due to
// `getStudentTvalue()`) in `getMoe()`, we need to do an iterative/heuristic
// search until the value is found.
export const getLengthForMoe = function ({
mean,
stdev,
min,
max,
precisionTarget,
}) {
export const getLengthForMoe = function ({ mean, stdev, min, max, precision }) {
const invertLength = areIdenticalMeasures(min, max)
? invertLengthIdentical.bind(undefined, precisionTarget)
: invertLengthNormal.bind(undefined, { mean, stdev, precisionTarget })
? invertLengthIdentical.bind(undefined, precision)
: invertLengthNormal.bind(undefined, { mean, stdev, precision })

const lengths = new Set([])
// eslint-disable-next-line fp/no-let
Expand All @@ -139,12 +133,12 @@ export const getLengthForMoe = function ({
return length
}

const invertLengthIdentical = function (precisionTarget, tValue) {
return (tValue * IDENTICAL_VARIANCE_SHIFT) / precisionTarget
const invertLengthIdentical = function (precision, tValue) {
return (tValue * IDENTICAL_VARIANCE_SHIFT) / precision
}

const invertLengthNormal = function ({ mean, stdev, precisionTarget }, tValue) {
return ((tValue * stdev) / (precisionTarget * mean)) ** 2
const invertLengthNormal = function ({ mean, stdev, precision }, tValue) {
return ((tValue * stdev) / (precision * mean)) ** 2
}

// Minimal `length` with a defined t-value
Expand Down

0 comments on commit 73f460d

Please sign in to comment.