HdrHistogram.NET
HdrHistogram.NET copied to clipboard
GetPerecentileOfValue
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?
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;
}