In my testing, I noticed that the hdr_max() and hdr_min() functions return a value that is not the true maximum or minimum recorded value. The true min/max values appear to be instead stored in min_value and max_value fields of the hdr_histogram struct.
It seems that the hdr_min() and hdr_max() functions return something that looks like an estimated value at the zero count instead of the actual limit value.
The function description for hdr_min() says Get minimum value from the histogram which I assumed means the real minimum recorded value instead of it being the estimated one based on the buckets and counts.
What's the purpose of these functions and would it be possible to document this difference a bit more clearly?
Here's my test program I used on Fedora 43 with GCC and HdrHistogram_c version 0.11.8:
#include <hdr/hdr_histogram.h>
#include <iostream>
#include <random>
#include <limits>
int main(int argc, char** argv)
{
std::default_random_engine rnd(std::random_device{}());
std::exponential_distribution<> dist(1);
hdr_histogram* hdr = nullptr;
hdr_init(1, 1 << 24, 2, &hdr);
int64_t min_val = std::numeric_limits<int64_t>::max();
int64_t max_val = std::numeric_limits<int64_t>::min();
for (int i = 1; i < 10000; i++)
{
int64_t value = dist(rnd) * 10000 + 1;
min_val = std::min(value, min_val);
max_val = std::max(value, max_val);
hdr_record_value(hdr, value);
}
std::cout << "min: " << min_val << " max: " << max_val << std::endl;
std::cout << "min_value: " << hdr->min_value << " max_value: " << hdr->max_value << std::endl;
std::cout << "hdr_min: " << hdr_min(hdr) << " hdr_max: " << hdr_max(hdr) << std::endl;
return 0;
}
And here's the output from one run:
min: 1 max: 79685
min_value: 1 max_value: 79685
hdr_min: 1 hdr_max: 79871
In my testing, I noticed that the
hdr_max()andhdr_min()functions return a value that is not the true maximum or minimum recorded value. The true min/max values appear to be instead stored inmin_valueandmax_valuefields of thehdr_histogramstruct.It seems that the
hdr_min()andhdr_max()functions return something that looks like an estimated value at the zero count instead of the actual limit value.The function description for
hdr_min()says Get minimum value from the histogram which I assumed means the real minimum recorded value instead of it being the estimated one based on the buckets and counts.What's the purpose of these functions and would it be possible to document this difference a bit more clearly?
Here's my test program I used on Fedora 43 with GCC and HdrHistogram_c version 0.11.8:
And here's the output from one run: