From 3c8ea73b3c895f52db34f88f1fb49d19bff486df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ion=20Gazta=C3=B1aga?= Date: Thu, 30 Jul 2026 01:31:36 +0200 Subject: [PATCH] Implement variable size MyFatInt --- bench/bench_utils.hpp | 79 ++++++++++---------------- experimental/bench_segmented_algos.cpp | 9 +-- 2 files changed, 34 insertions(+), 54 deletions(-) diff --git a/bench/bench_utils.hpp b/bench/bench_utils.hpp index 73241ba..10359d1 100644 --- a/bench/bench_utils.hpp +++ b/bench/bench_utils.hpp @@ -173,78 +173,57 @@ class MyInt friend bool operator>=(const MyInt& a, const MyInt& b) { return a.int_ >= b.int_; } }; +//MyFatInt: same idea as MyInt but storing Count ints (32 bytes by default) so +//benchmarks can also measure bigger elements, whose special member functions do +//proportionally more work. Only the first int participates in int_value() and +//in the comparison operators; the remaining ones are payload that the copy and +//destroy operations must still touch. +template class MyFatInt { - int int0_; - int int1_; - int int2_; - int int3_; - int int4_; - int int5_; - int int6_; - int int7_; + int ints_[Count]; public: inline explicit MyFatInt(int i = 0) - : int0_(i++) - , int1_(i++) - , int2_(i++) - , int3_(i++) - , int4_(i++) - , int5_(i++) - , int6_(i++) - , int7_(i++) - {} + { + for(std::size_t n = 0; n != Count; ++n) + ints_[n] = i++; + } inline MyFatInt(const MyFatInt &other) - : int0_(other.int0_) - , int1_(other.int1_) - , int2_(other.int2_) - , int3_(other.int3_) - , int4_(other.int4_) - , int5_(other.int5_) - , int6_(other.int6_) - , int7_(other.int7_) - {} + { + for(std::size_t n = 0; n != Count; ++n) + ints_[n] = other.ints_[n]; + } inline MyFatInt & operator=(const MyFatInt &other) { - int0_ = other.int0_; - int1_ = other.int1_; - int2_ = other.int2_; - int3_ = other.int3_; - int4_ = other.int4_; - int5_ = other.int5_; - int6_ = other.int6_; - int7_ = other.int7_; + for(std::size_t n = 0; n != Count; ++n) + ints_[n] = other.ints_[n]; return *this; } inline ~MyFatInt() { - int0_ = 0; - int1_ = 0; - int2_ = 0; - int3_ = 0; - int4_ = 0; - int5_ = 0; - int6_ = 0; - int7_ = 0; + for(std::size_t n = 0; n != Count; ++n) + ints_[n] = 0; } - inline int int_value() const { return int0_; } + inline int int_value() const { return ints_[0]; } - friend inline bool operator==(const MyFatInt& a, const MyFatInt& b) { return a.int0_ == b.int0_; } - friend inline bool operator!=(const MyFatInt& a, const MyFatInt& b) { return a.int0_ != b.int0_; } - friend inline bool operator<(const MyFatInt& a, const MyFatInt& b) { return a.int0_ < b.int0_; } - friend inline bool operator>(const MyFatInt& a, const MyFatInt& b) { return a.int0_ > b.int0_; } - friend inline bool operator<=(const MyFatInt& a, const MyFatInt& b) { return a.int0_ <= b.int0_; } - friend inline bool operator>=(const MyFatInt& a, const MyFatInt& b) { return a.int0_ >= b.int0_; } + friend inline bool operator==(const MyFatInt& a, const MyFatInt& b) { return a.ints_[0] == b.ints_[0]; } + friend inline bool operator!=(const MyFatInt& a, const MyFatInt& b) { return a.ints_[0] != b.ints_[0]; } + friend inline bool operator<(const MyFatInt& a, const MyFatInt& b) { return a.ints_[0] < b.ints_[0]; } + friend inline bool operator>(const MyFatInt& a, const MyFatInt& b) { return a.ints_[0] > b.ints_[0]; } + friend inline bool operator<=(const MyFatInt& a, const MyFatInt& b) { return a.ints_[0] <= b.ints_[0]; } + friend inline bool operator>=(const MyFatInt& a, const MyFatInt& b) { return a.ints_[0] >= b.ints_[0]; } }; inline int int_value(int x) { return x; } inline int int_value(const MyInt& x) { return x.int_value(); } -inline int int_value(const MyFatInt& x) { return x.int_value(); } + +template +inline int int_value(const MyFatInt& x) { return x.int_value(); } //Benchmark element. The NonTrivial boolean (chosen by the caller, true by //default) selects between two layouts of identical size: diff --git a/experimental/bench_segmented_algos.cpp b/experimental/bench_segmented_algos.cpp index ff118bf..1fcd9d8 100644 --- a/experimental/bench_segmented_algos.cpp +++ b/experimental/bench_segmented_algos.cpp @@ -84,7 +84,7 @@ #include "../bench/bench_utils.hpp" #ifndef BOOST_CONTAINER_BENCH_SEGMENTED_GROUP -//#define BOOST_CONTAINER_BENCH_SEGMENTED_GROUP 15 +#define BOOST_CONTAINER_BENCH_SEGMENTED_GROUP 20 #endif //BOOST_CONTAINER_BENCH_SEGMENTED_GROUP namespace bc = boost::container; @@ -654,6 +654,7 @@ inline void print_group_header(int group, const char* desc, const char* vtname) { g_group_geomean.reset(); std::cout << "\n===== Group " << group << ": " << desc << " [" << vtname << "] =====\n"; + print_subheader(); } inline void print_group_geomean() @@ -2112,7 +2113,6 @@ void run_all(const C& c, std::size_t iters, const char* cname) vec_t cv(c.begin(), c.end()); g_geomean.reset(); - print_subheader(); ////////////////////////////////////////////////////////////////// // Group 10: single range, sequential access @@ -2526,7 +2526,7 @@ void run_benchmarks() //#define BENCH_ON #if defined(NDEBUG) && defined(BENCH_ON) const std::size_t N = 100000; - const std::size_t iter = 5000; + const std::size_t iter = 5000; #else const std::size_t N = 10000; const std::size_t iter = 1; @@ -2554,6 +2554,7 @@ int main() { //run_benchmarks(); run_benchmarks(); - run_benchmarks(); + run_benchmarks >(); + run_benchmarks >(); return 0; }