Skip to content

Instantly share code, notes, and snippets.

@mqp
Created November 5, 2016 00:10
Show Gist options
  • Save mqp/0fff4a03f12214c1775c9d302c830c10 to your computer and use it in GitHub Desktop.
Save mqp/0fff4a03f12214c1775c9d302c830c10 to your computer and use it in GitHub Desktop.
Incremental mystery metric computation
internal void UpdateRoundTripTimeAndVariance(int lastRoundtripTime)
{
if (lastRoundtripTime < 0)
{
return;
}
this.roundTripTimeVariance -= this.roundTripTimeVariance / 4;
if (lastRoundtripTime >= this.roundTripTime)
{
this.roundTripTime += (lastRoundtripTime - this.roundTripTime) / 8;
this.roundTripTimeVariance += (lastRoundtripTime - this.roundTripTime) / 4;
}
else
{
this.roundTripTime += (lastRoundtripTime - this.roundTripTime) / 8;
this.roundTripTimeVariance -= (lastRoundtripTime - this.roundTripTime) / 4;
}
if (this.roundTripTime < this.lowestRoundTripTime)
{
this.lowestRoundTripTime = this.roundTripTime;
}
if (this.roundTripTimeVariance <= this.highestRoundTripTimeVariance)
{
return;
}
this.highestRoundTripTimeVariance = this.roundTripTimeVariance;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment