static bool compare_histogram(struct hdr_histogram* a, struct hdr_histogram* b) { size_t a_size = hdr_get_memory_size(a); size_t b_size = hdr_get_memory_size(b); if (a_size == b_size && memcmp(a, b, a_size) == 0) { return true; } printf("Sizes a: %zu, b: %zu\n", a_size, b_size); struct hdr_iter iter_a; struct hdr_iter iter_b; hdr_iter_init(&iter_a, a); hdr_iter_init(&iter_b, b); while (hdr_iter_next(&iter_a) && hdr_iter_next(&iter_b)) { if (iter_a.count_at_index != iter_b.count_at_index || iter_a.value_from_index != iter_b.value_from_index) { printf( "A - value: %"PRIu64", count: %"PRIu64", B - value: %"PRIu64", count: %"PRIu64"\n", iter_a.value_from_index, iter_a.count_at_index, iter_b.value_from_index, iter_b.count_at_index); } } return false; }
long double stats_within_stdev(stats *stats, long double mean, long double stdev, uint64_t n) { long double upper = mean + (stdev * n); long double lower = mean - (stdev * n); if (stats->histogram != NULL) { int64_t total_count = stats->histogram->total_count; if (total_count == 0) { return 0.0; } int64_t upper_value = upper; int64_t lower_value = lower; struct hdr_iter iter; hdr_iter_init(&iter, stats->histogram); int64_t lower_count = 0; int64_t upper_count = 0; bool found_upper = false; while (hdr_iter_next(&iter)) { if (lower_value > iter.value_from_index) { lower_count = iter.count_to_index; } if (upper_value < iter.highest_equivalent_value) { upper_count = iter.count_to_index; found_upper = true; break; } } if (!found_upper) { upper_count = total_count; } return 100.0 * (upper_count - lower_count) / (double) total_count; } uint64_t sum = 0; for (uint64_t i = 0; i < stats->limit; i++) { uint64_t x = stats->data[i]; if (x >= lower && x <= upper) sum++; } return (sum / (long double) stats->limit) * 100; }
static bool compare_histogram(struct hdr_histogram* a, struct hdr_histogram* b) { if (a->counts_len != b->counts_len) { printf( "a.counts_len = %"PRIu32", b.counts_len = %"PRIu32"\n", a->counts_len, b->counts_len); return false; } int64_t a_max = hdr_max(a); int64_t b_max = hdr_max(b); if (a_max != b_max) { printf("a.max = %"PRIu64", b.max = %"PRIu64"\n", a_max, b_max); // return false; } int64_t a_min = hdr_min(a); int64_t b_min = hdr_min(b); if (a_min != b_min) { printf("a.min = %"PRIu64", b.min = %"PRIu64"\n", a_min, b_min); // return false; } size_t a_size = hdr_get_memory_size(a); size_t b_size = hdr_get_memory_size(b); if (a_size != b_size) { printf("a.size: %zu, b.size: %zu\n", a_size, b_size); return false; } size_t counts_size = a->counts_len * sizeof(int64_t); if (memcmp(a->counts, b->counts, counts_size) == 0) { return true; } printf("%s\n", "Counts incorrect"); struct hdr_iter iter_a; struct hdr_iter iter_b; hdr_iter_init(&iter_a, a); hdr_iter_init(&iter_b, b); while (hdr_iter_next(&iter_a) && hdr_iter_next(&iter_b)) { if (iter_a.count != iter_b.count || iter_a.value != iter_b.value) { printf( "A - value: %"PRIu64", count: %"PRIu64", B - value: %"PRIu64", count: %"PRIu64"\n", iter_a.value, iter_a.count, iter_b.value, iter_b.count); } } return false; }