Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GetPerecentileOfValue #79

Open
hannasm opened this issue Jul 1, 2022 · 1 comment
Open

GetPerecentileOfValue #79

hannasm opened this issue Jul 1, 2022 · 1 comment

Comments

@hannasm
Copy link

hannasm commented Jul 1, 2022

How hard would it be to add a method that queries the histogram for a percentile given a sample?

If i have a measurement of 300ms what percentile does this sample fall under?

@hannasm
Copy link
Author

hannasm commented Jul 1, 2022

I haven't actually compiled this but here's my 15-minute guess:

public double GetPercentileForValue(long value) {
  var bucketIndex = GetBucketIndex(value);
  var subBucketIndex = GetSubBucketIndex(value, bucketIndex);
  long runningCount = 0;
  for (var i = 0; i < BucketCount; i++) {
    var j = (i==0) ? 0 : (SubBucketCount / 2);
    for (;j < SubBucketCount;j++) {
      runningCount += GetCountAt(i,j);
      if (i == bucketIndex && j == subBucketIndex) { return (runningCount / TotalCount) * 100.0; }
    }
  }

  return 100;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant