50 auto unshifted = polynomials.get_unshifted();
51 auto all_labels = polynomials.get_labels();
55 size_t alloc_size = 0;
56 size_t virtual_size = 0;
58 size_t fit_4bytes = 0;
59 size_t fit_8bytes = 0;
60 size_t fit_16bytes = 0;
61 size_t fit_32bytes = 0;
62 size_t actual_mem = 0;
63 double compressed_mem = 0;
68 totals.name =
"TOTAL";
71 for (
auto& poly : unshifted) {
73 stats.name = (idx < all_labels.size()) ? all_labels[idx] :
"unknown_" +
std::to_string(idx);
76 if (poly.is_empty()) {
81 stats.alloc_size = poly.size();
82 stats.virtual_size = poly.virtual_size();
83 stats.actual_mem = stats.alloc_size *
sizeof(
Fr);
86 for (
size_t i = 0; i < stats.alloc_size; ++i) {
89 if (elem.
data[0] == 0 && elem.
data[1] == 0 && elem.
data[2] == 0 && elem.
data[3] == 0) {
97 if (bytes_needed <= 4) {
99 stats.compressed_mem += 4;
100 }
else if (bytes_needed <= 8) {
102 stats.compressed_mem += 8;
103 }
else if (bytes_needed <= 16) {
105 stats.compressed_mem += 16;
108 stats.compressed_mem += 32;
113 totals.alloc_size += stats.alloc_size;
114 totals.virtual_size += stats.virtual_size;
115 totals.num_zeros += stats.num_zeros;
116 totals.fit_4bytes += stats.fit_4bytes;
117 totals.fit_8bytes += stats.fit_8bytes;
118 totals.fit_16bytes += stats.fit_16bytes;
119 totals.fit_32bytes += stats.fit_32bytes;
120 totals.actual_mem += stats.actual_mem;
121 totals.compressed_mem += stats.compressed_mem;
127 auto mb = [](
auto bytes) {
return static_cast<double>(bytes) / (1024.0 * 1024.0); };
129 std::ostringstream oss;
130 oss <<
"\n=== Polynomial Memory Analysis ===\n";
131 oss << std::left <<
std::setw(36) <<
"Polynomial"
132 <<
" | " << std::right <<
std::setw(10) <<
"AllocSize"
141 oss << std::string(140,
'-') <<
"\n";
143 auto print_row = [&](
const PolyStats& s) {
144 if (s.alloc_size == 0 && s.name !=
"TOTAL") {
147 oss << std::left <<
std::setw(36) << s.name <<
" | " << std::right <<
std::setw(10) << s.alloc_size <<
" | "
149 << s.fit_8bytes <<
" | " <<
std::setw(10) << s.fit_16bytes <<
" | " <<
std::setw(10) << s.fit_32bytes
154 for (
const auto& s : all_stats) {
157 oss << std::string(140,
'-') <<
"\n";
161 totals.actual_mem > 0 ? 100.0 * (1.0 - totals.compressed_mem /
static_cast<double>(totals.actual_mem)) : 0.0;