Skip to content

Commit

Permalink
Add comments
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky committed Dec 5, 2021
1 parent a3783b4 commit 7a6b0d6
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/run/sample/time_duration.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
import { getMean } from '../../stats/sum.js'

// We try to make every sample last the same duration `targetSampleDuration`.
// We do it by keeping track of `timeDuration`, the duration per task function
// (including inside the `repeat` loop).
// However, this is difficult when the task has a high variance because we base
// our estimation on:
// - The mean duration of the task, which might vary in the next sample
// - The duration of the task in the previous sample, which might have been
// very slow or fast.
// We soften the second problem by basing our estimation on multiple previous
// samples instead of a single one.
export const getTimeDuration = function ({
timeDurations,
measureDuration,
Expand All @@ -13,6 +23,8 @@ export const getTimeDuration = function ({
return { timeDurations: timeDurationsB, timeDurationMean }
}

// Retrieve previous `timeDurations`.
// We never keep uncalibrated ones.
const getTimeDurations = function (timeDurations, calibrated) {
if (!calibrated) {
return []
Expand All @@ -23,4 +35,8 @@ const getTimeDurations = function (timeDurations, calibrated) {
: timeDurations
}

// Max amount of `timeDurations` to keep.
// A lower value makes the sample duration of tasks with high variance vary more
// A higher value makes the sample duration more likely to be too slow or fast
// when the task duration becomes suddenly much faster or slower.
const TIME_DURATIONS_LENGTH = 3

0 comments on commit 7a6b0d6

Please sign in to comment.