Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky committed Dec 12, 2021
1 parent 4691e60 commit 1b701fc
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/stats/cold.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ export const getCold = function (
length = array.filter(filter).length,
},
) {
const minIndex = getIndex(COLD_MIN_PERCENTAGE, length)
const maxIndex = getIndex(COLD_MAX_PERCENTAGE, length)
const minIndex = getIndexFromLength(COLD_MIN_PERCENTAGE, length)
const maxIndex = getIndexFromLength(COLD_MAX_PERCENTAGE, length)
const closestMean = getClosestMean(array, {
mean,
minIndex,
Expand All @@ -50,7 +50,7 @@ export const getColdLoopsLeft = function (
) {
const incrementalMeanMin = mean * (1 - precisionTarget)
const incrementalMeanMax = mean * (1 + precisionTarget)
const minIndex = getIndex(COLD_MAX_PERCENTAGE, length)
const minIndex = getIndexFromLength(COLD_MAX_PERCENTAGE, length)
const maxIndex = length - 1
const closestMeanIndex = getClosestMeanIndex(array, {
minIndex,
Expand All @@ -60,7 +60,7 @@ export const getColdLoopsLeft = function (
incrementalMeanMax,
})
const coldLoopsLeft =
Math.ceil(closestMeanIndex / COLD_MAX_PERCENTAGE) + 1 - length
getLengthFromIndex(COLD_MAX_PERCENTAGE, closestMeanIndex) - length
return coldLoopsLeft
}

Expand Down Expand Up @@ -108,10 +108,14 @@ const getClosestMeanIndex = function (
/* eslint-enable max-statements, complexity, fp/no-let, fp/no-loops,
fp/no-mutation, max-depth, no-continue */

const getIndex = function (percentage, length) {
const getIndexFromLength = function (percentage, length) {
return Math.floor(percentage * (length - 1))
}

const getLengthFromIndex = function (percentage, index) {
return Math.ceil(index / percentage) + 1
}

// The very first measures are sometimes abnormally fast.
// - This will make `cold` abnormally low as well, which can make the benchmark
// end too early.
Expand Down

0 comments on commit 1b701fc

Please sign in to comment.