Skip to content

Commit 77952aa

Browse files
committed
Refactor segmented benches in groups, added additional bench to search_n
1 parent acfe58c commit 77952aa

1 file changed

Lines changed: 78 additions & 41 deletions

File tree

experimental/bench_segmented_algos.cpp

Lines changed: 78 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@
8585
#include <boost/container/experimental/wrapped_iterator.hpp>
8686
#include "../bench/bench_utils.hpp"
8787

88-
#define BOOST_CONTAINER_BENCH_SEGMENTED_GROUP 1
88+
#define BOOST_CONTAINER_BENCH_SEGMENTED_GROUP 10
8989
#define BOOST_CONTAINER_BENCH_SEGMENTED_BIDIR_ENABLED 0
9090

9191
namespace bc = boost::container;
@@ -2181,7 +2181,7 @@ void run_all(const C& c, std::size_t iters, const char* cname)
21812181
//////////////////////////////////////////////////////////////////
21822182
// Group 1: Algorithms with a single range
21832183
//////////////////////////////////////////////////////////////////
2184-
#if !defined(BOOST_CONTAINER_BENCH_SEGMENTED_GROUP) || BOOST_CONTAINER_BENCH_SEGMENTED_GROUP == 0 || BOOST_CONTAINER_BENCH_SEGMENTED_GROUP == 1
2184+
#if !defined(BOOST_CONTAINER_BENCH_SEGMENTED_GROUP) || BOOST_CONTAINER_BENCH_SEGMENTED_GROUP == 0 || BOOST_CONTAINER_BENCH_SEGMENTED_GROUP == 10
21852185

21862186
//all_of
21872187
bench_all_of(c, iters, cname, is_zero_or_positive<VT>(), "all_of(hit)");
@@ -2248,6 +2248,43 @@ void run_all(const C& c, std::size_t iters, const char* cname)
22482248
bench_is_partitioned(c2, iters, cname, is_negative<VT>(), "is_partitioned(miss)");
22492249
}
22502250

2251+
//none_of
2252+
bench_none_of(c, iters, cname, is_negative<VT>(), "none_of(hit)");
2253+
bench_none_of(c, iters, cname, equal_to_ref<VT>(VT(static_cast<int>(c.size()/2))), "none_of(miss)");
2254+
2255+
#if !defined(BOOST_CONTAINER_BENCH_SEGMENTED_BIDIR_ENABLED) || BOOST_CONTAINER_BENCH_SEGMENTED_BIDIR_ENABLED
2256+
//partition
2257+
bench_partition(c, iters, cname, is_odd<VT>(), "partition(hit)");
2258+
bench_partition(c, iters, cname, is_negative<VT>(), "partition(miss)");
2259+
#endif
2260+
2261+
//replace
2262+
{
2263+
C c2(c);
2264+
is_odd<VT> is_odd_pred;
2265+
for (typename C::iterator it = c2.begin(); it != c2.end(); ++it){
2266+
if( is_odd_pred(*it) )
2267+
*it = min1;
2268+
}
2269+
bench_replace(c2, iters, cname, min1, VT(-2), "replace(hit)");
2270+
}
2271+
bench_replace(c, iters, cname, min1, VT(-2), "replace(miss)");
2272+
2273+
//replace_if
2274+
bench_replace_if(c, iters, cname, is_odd<VT>(), VT(-2), "replace_if(hit)");
2275+
bench_replace_if(c, iters, cname, is_negative<VT>(), VT(-2), "replace_if(miss)");
2276+
2277+
//stable_partition (not tested since it's not optimized for random access iterators)
2278+
//bench_stable_partition(c, iters, cname, is_odd<VT>(), "stable_partition(hit)");
2279+
//bench_stable_partition(c, iters, cname, is_negative<VT>(), "stable_partition(miss)");
2280+
2281+
#endif
2282+
2283+
//////////////////////////////////////////////////////////////////
2284+
// Group 1.5: Algorithms with 1 range but two iterational directions
2285+
//////////////////////////////////////////////////////////////////
2286+
#if !defined(BOOST_CONTAINER_BENCH_SEGMENTED_GROUP) || BOOST_CONTAINER_BENCH_SEGMENTED_GROUP == 0 || BOOST_CONTAINER_BENCH_SEGMENTED_GROUP == 15
2287+
22512288
//is_sorted
22522289
{
22532290
bench_is_sorted(c, iters, cname, "is_sorted(hit)");
@@ -2264,70 +2301,61 @@ void run_all(const C& c, std::size_t iters, const char* cname)
22642301
bench_is_sorted_until(c2, iters, cname, "is_sorted_until(miss)");
22652302
}
22662303

2267-
//none_of
2268-
bench_none_of(c, iters, cname, is_negative<VT>(), "none_of(hit)");
2269-
bench_none_of(c, iters, cname, equal_to_ref<VT>(VT(static_cast<int>(c.size()/2))), "none_of(miss)");
2270-
2271-
//partition
2272-
bench_partition(c, iters, cname, is_odd<VT>(), "partition(hit)");
2273-
bench_partition(c, iters, cname, is_negative<VT>(), "partition(miss)");
2274-
22752304
//partition_point (not tested since it's not optimized for random access iterators)
22762305
//bench_partition_point(c, iters, cname, less_than_ref<VT>(static_cast<VT>((int)c.size()/2)), "partition_point(hit)");
22772306
//bench_partition_point(c, iters, cname, is_zero_or_positive<VT>(), "partition_point(miss)");
22782307

22792308
//remove
2309+
22802310
bench_remove(c, iters, cname, half, "remove(hit)");
22812311
bench_remove(c, iters, cname, min1, "remove(miss)");
22822312

22832313
//remove_if
22842314
bench_remove_if(c, iters, cname, less_and_greater_ref<VT>(quart, threequart), "remove_if(hit)");
22852315
bench_remove_if(c, iters, cname, is_negative<VT>(), "remove_if(miss)");
22862316

2287-
//replace
2288-
{
2289-
C c2(c);
2290-
is_odd<VT> is_odd_pred;
2291-
for (typename C::iterator it = c2.begin(); it != c2.end(); ++it){
2292-
if( is_odd_pred(*it) )
2293-
*it = min1;
2294-
}
2295-
bench_replace(c2, iters, cname, min1, VT(-2), "replace(hit)");
2296-
}
2297-
bench_replace(c, iters, cname, min1, VT(-2), "replace(miss)");
2298-
2299-
//replace_if
2300-
bench_replace_if(c, iters, cname, is_odd<VT>(), VT(-2), "replace_if(hit)");
2301-
bench_replace_if(c, iters, cname, is_negative<VT>(), VT(-2), "replace_if(miss)");
2302-
23032317
#if !defined(BOOST_CONTAINER_BENCH_SEGMENTED_BIDIR_ENABLED) || BOOST_CONTAINER_BENCH_SEGMENTED_BIDIR_ENABLED
23042318
//reverse
23052319
bench_reverse(c, iters, cname);
23062320
#endif
23072321

2308-
//search
2309-
{
2310-
int ihalf = static_cast<int>(c.size() / 2);
2311-
VT hit_pat[] = {half, VT(ihalf + 1), VT(ihalf + 2)};
2312-
bench_search(c, iters, cname, hit_pat, 3, "search(hit)");
2313-
VT miss_pat[] = {min1, VT(-2), VT(-3)};
2314-
bench_search(c, iters, cname, miss_pat, 3, "search(miss)");
2315-
}
2316-
23172322
//search_n
2318-
bench_search_n(c, iters, cname, 1, half, "search_n(hit)");
2323+
bench_search_n(c, iters, cname, 1, half, "search_n(1hit)");
23192324
bench_search_n(c, iters, cname, 3, min1, "search_n(miss)");
23202325

2321-
//stable_partition (not tested since it's not optimized for random access iterators)
2322-
//bench_stable_partition(c, iters, cname, is_odd<VT>(), "stable_partition(hit)");
2323-
//bench_stable_partition(c, iters, cname, is_negative<VT>(), "stable_partition(miss)");
2326+
//search_n with decoy runs + a real match of 8 in the middle
2327+
{
2328+
C c_sn(c);
2329+
const std::size_t sz = c_sn.size();
2330+
const std::size_t mid = sz / 2;
2331+
2332+
// Place decoy runs of min1 in the first half (lengths 2, 4, 6)
2333+
// spaced out so they don't overlap
2334+
const std::size_t gap = mid / 4;
2335+
const std::size_t decoy_runs[] = { 2, 4, 6 };
2336+
for(std::size_t d = 0; d < 3; ++d) {
2337+
const std::size_t pos = gap * (d + 1) - decoy_runs[d];
2338+
typename C::iterator it = boost::container::make_iterator_uadvance(c_sn.begin(), pos);
2339+
for(std::size_t k = 0; k < decoy_runs[d]; ++k, ++it)
2340+
*it = min1;
2341+
}
2342+
2343+
// Place the real match of 8 consecutive min1 values at the middle
2344+
{
2345+
typename C::iterator it = boost::container::make_iterator_uadvance(c_sn.begin(), mid);
2346+
for(std::size_t k = 0; k < 8; ++k, ++it)
2347+
*it = min1;
2348+
}
2349+
2350+
bench_search_n(c_sn, iters, cname, 8, min1, "search_n(8mid)");
2351+
}
23242352

23252353
#endif
23262354

23272355
//////////////////////////////////////////////////////////////////
23282356
// Group 2: Algorithms with 2 ranges
23292357
//////////////////////////////////////////////////////////////////
2330-
#if !defined(BOOST_CONTAINER_BENCH_SEGMENTED_GROUP) || BOOST_CONTAINER_BENCH_SEGMENTED_GROUP == 0 || BOOST_CONTAINER_BENCH_SEGMENTED_GROUP == 2
2358+
#if !defined(BOOST_CONTAINER_BENCH_SEGMENTED_GROUP) || BOOST_CONTAINER_BENCH_SEGMENTED_GROUP == 0 || BOOST_CONTAINER_BENCH_SEGMENTED_GROUP == 20
23312359

23322360
//copy
23332361
bench_copy<C, vec_t>(c, iters, cname, "copy(1S)");
@@ -2416,6 +2444,15 @@ void run_all(const C& c, std::size_t iters, const char* cname)
24162444
bench_reverse_copy<C, C >(c, iters, cname, "reverse_copy(2xS)");
24172445
#endif
24182446

2447+
//search
2448+
{
2449+
int ihalf = static_cast<int>(c.size() / 2);
2450+
VT hit_pat[] = {half, VT(ihalf + 1), VT(ihalf + 2)};
2451+
bench_search(c, iters, cname, hit_pat, 3, "search(hit)");
2452+
VT miss_pat[] = {min1, VT(-2), VT(-3)};
2453+
bench_search(c, iters, cname, miss_pat, 3, "search(miss)");
2454+
}
2455+
24192456
//swap_ranges
24202457
bench_swap_ranges(c, iters, cname);
24212458

@@ -2427,7 +2464,7 @@ void run_all(const C& c, std::size_t iters, const char* cname)
24272464
//////////////////////////////////////////////////////////////////
24282465
// Group 3: Algorithms with 3 ranges
24292466
//////////////////////////////////////////////////////////////////
2430-
#if !defined(BOOST_CONTAINER_BENCH_SEGMENTED_GROUP) || BOOST_CONTAINER_BENCH_SEGMENTED_GROUP == 0 || BOOST_CONTAINER_BENCH_SEGMENTED_GROUP == 3
2467+
#if !defined(BOOST_CONTAINER_BENCH_SEGMENTED_GROUP) || BOOST_CONTAINER_BENCH_SEGMENTED_GROUP == 0 || BOOST_CONTAINER_BENCH_SEGMENTED_GROUP == 30
24312468

24322469
//merge
24332470
{

0 commit comments

Comments
 (0)