Created
August 19, 2021 11:56
-
-
Save kota1921/2ed5db85b4aff425246528862a2e4aaa to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun onNextIteration(durationNs: Long): Boolean { | |
iteration++ | |
totalDuration += durationNs | |
if (iteration == 1) { | |
fastMovingAvg = durationNs.toFloat() | |
slowMovingAvg = durationNs.toFloat() | |
return false | |
} | |
fastMovingAvg = FAST_RATIO * durationNs + (1 - FAST_RATIO) * fastMovingAvg | |
slowMovingAvg = SLOW_RATIO * durationNs + (1 - SLOW_RATIO) * slowMovingAvg | |
// If fast moving avg is close to slow, the benchmark is stabilizing | |
val ratio = fastMovingAvg / slowMovingAvg | |
if (ratio < 1 + THRESHOLD && ratio > 1 - THRESHOLD) { | |
similarIterationCount++ | |
} else { | |
similarIterationCount = 0 | |
} | |
if (iteration >= MIN_ITERATIONS && totalDuration >= MIN_DURATION_NS) { | |
if (similarIterationCount > MIN_SIMILAR_ITERATIONS || | |
totalDuration >= MAX_DURATION_NS) { | |
// benchmark has stabilized, or we're out of time | |
return true | |
} | |
} | |
return false | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment