Skip to content

Commit

Permalink
Split file
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky committed Dec 5, 2021
1 parent 8fa44a7 commit a3783b4
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 26 deletions.
27 changes: 1 addition & 26 deletions src/run/sample/state.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { appendArray } from '../../stats/append.js'
import { mergeSort } from '../../stats/merge.js'
import { getMean } from '../../stats/sum.js'

import { getMaxMeasuresLeft } from './max_measures.js'
import { normalizeSampleMeasures } from './normalize.js'
import { handleRepeat } from './repeat.js'
import { getTimeDuration } from './time_duration.js'

// Returns initial `sampleState`
export const getInitialSampleState = function () {
Expand Down Expand Up @@ -92,31 +92,6 @@ const addSampleMeasures = function ({
return { measures, unsortedMeasures }
}

const getTimeDuration = function ({
timeDurations,
measureDuration,
sampleTimes,
calibrated,
}) {
const timeDuration = measureDuration / sampleTimes
const timeDurationsA = getTimeDurations(timeDurations, calibrated)
const timeDurationsB = [...timeDurationsA, timeDuration]
const timeDurationMean = getMean(timeDurationsB)
return { timeDurations: timeDurationsB, timeDurationMean }
}

const getTimeDurations = function (timeDurations, calibrated) {
if (!calibrated) {
return []
}

return timeDurations.length === MEASURE_DURATIONS_MAX
? timeDurations.slice(1)
: timeDurations
}

const MEASURE_DURATIONS_MAX = 3

// `maxLoops` is the number of `repeat` loops the sample should measure.
// Each sample needs to perform a specific amount of measures (`maxLoops`).
// We do this instead of passing a maximum duration instead because:
Expand Down
26 changes: 26 additions & 0 deletions src/run/sample/time_duration.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { getMean } from '../../stats/sum.js'

export const getTimeDuration = function ({
timeDurations,
measureDuration,
sampleTimes,
calibrated,
}) {
const timeDuration = measureDuration / sampleTimes
const timeDurationsA = getTimeDurations(timeDurations, calibrated)
const timeDurationsB = [...timeDurationsA, timeDuration]
const timeDurationMean = getMean(timeDurationsB)
return { timeDurations: timeDurationsB, timeDurationMean }
}

const getTimeDurations = function (timeDurations, calibrated) {
if (!calibrated) {
return []
}

return timeDurations.length === TIME_DURATIONS_LENGTH
? timeDurations.slice(1)
: timeDurations
}

const TIME_DURATIONS_LENGTH = 3

0 comments on commit a3783b4

Please sign in to comment.