From 2e78cb524c599a8392ca3eb2bcde0e7d7f1528a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ion=20Gazta=C3=B1aga?= Date: Tue, 11 Aug 2020 23:49:13 +0200 Subject: [PATCH] Unroll operation loop to avoid measuring loop overhead and other modifications to exercise more paths of the insertion functions. --- bench/bench_vectors.cpp | 37 +++++++++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/bench/bench_vectors.cpp b/bench/bench_vectors.cpp index 8e3665d..1fae391 100644 --- a/bench/bench_vectors.cpp +++ b/bench/bench_vectors.cpp @@ -134,7 +134,7 @@ struct insert_near_end_repeated template BOOST_CONTAINER_FORCEINLINE void operator()(C &c, int i) - { c.insert(c.size() >= RangeSize ? c.end()-RangeSize : c.begin(), RangeSize, MyInt(i)); } + { c.insert(c.size() >= 2*RangeSize ? c.end()-2*RangeSize : c.begin(), RangeSize, MyInt(i)); } BOOST_CONTAINER_FORCEINLINE const char *name() const { return "insert_near_end_repeated"; } @@ -148,11 +148,11 @@ struct insert_near_end_range template BOOST_CONTAINER_FORCEINLINE void operator()(C &c, int) { - c.insert(c.size() >= RangeSize ? c.end()-RangeSize : c.begin(), &a[0], &a[0]+RangeSize); + c.insert(c.size() >= 2*RangeSize ? c.end()-2*RangeSize : c.begin(), &a[0], &a[0]+RangeSize); } BOOST_CONTAINER_FORCEINLINE const char *name() const - { return "insert_near_end_repeated"; } + { return "insert_near_end_range"; } MyInt a[RangeSize]; }; @@ -167,7 +167,7 @@ struct insert_near_end { typedef typename C::iterator it_t; it_t it (c.end()); - it -= static_cast(!c.empty()); + it -= static_cast(c.size() >= 2)*2; c.insert(it, MyInt(i)); } @@ -187,24 +187,41 @@ void vector_test_template(std::size_t num_iterations, std::size_t num_elements, Operation op; const typename Container::size_type multiplier = op.capacity_multiplier(); - //Warm-up operations + //Warm-up operation for(std::size_t e = 0, max = num_elements/multiplier; e != max; ++e){ op(c, static_cast(e)); } c.clear(); cpu_timer timer; - timer.start(); + const std::size_t max = num_elements/multiplier; for(std::size_t r = 0; r != num_iterations; ++r){ - for(std::size_t e = 0, max = num_elements/multiplier; e != max; ++e){ - op(c, static_cast(e)); + //Unrolll the loop to avoid noise from loop code + int i = 0; + timer.resume(); + for(std::size_t e = 0; e < max/16; ++e){ + op(c, static_cast(i++)); + op(c, static_cast(i++)); + op(c, static_cast(i++)); + op(c, static_cast(i++)); + op(c, static_cast(i++)); + op(c, static_cast(i++)); + op(c, static_cast(i++)); + op(c, static_cast(i++)); + op(c, static_cast(i++)); + op(c, static_cast(i++)); + op(c, static_cast(i++)); + op(c, static_cast(i++)); + op(c, static_cast(i++)); + op(c, static_cast(i++)); + op(c, static_cast(i++)); + op(c, static_cast(i++)); } timer.stop(); c.clear(); - timer.resume(); } timer.stop(); @@ -216,7 +233,7 @@ void vector_test_template(std::size_t num_iterations, std::size_t num_elements, std::cout << cont_name << "->" << op.name() <<" ns: " << float(nseconds)/(num_iterations*num_elements) << '\t' - << "Capacity: " << (unsigned int)capacity + << "Capacity: " << capacity << "\n"; }