@@ -59,7 +59,7 @@ void associative_container_benchmarks(std::string container) {
59
59
auto get_key = [](Value const & v) { return adapt_operations<Container>::key_from_value (v); };
60
60
61
61
auto bench = [&](std::string operation, auto f) {
62
- benchmark::RegisterBenchmark (container + " ::" + operation, f)->Arg (32 )->Arg (1024 )->Arg (8192 );
62
+ benchmark::RegisterBenchmark (container + " ::" + operation, f)->Arg (0 )-> Arg ( 32 )->Arg (1024 )->Arg (8192 );
63
63
};
64
64
65
65
static constexpr bool is_multi_key_container =
@@ -176,7 +176,7 @@ void associative_container_benchmarks(std::string container) {
176
176
// Insertion
177
177
// ///////////////////////
178
178
bench (" insert(value) (already present)" , [=](auto & st) {
179
- const std::size_t size = st.range (0 );
179
+ const std::size_t size = st.range (0 ) ? st. range ( 0 ) : 1 ;
180
180
std::vector<Value> in = make_value_types (generate_unique_keys (size));
181
181
Value to_insert = in[in.size () / 2 ]; // pick any existing value
182
182
std::vector<Container> c (BatchSize, Container (in.begin (), in.end ()));
@@ -371,7 +371,7 @@ void associative_container_benchmarks(std::string container) {
371
371
// Erasure
372
372
// ///////////////////////
373
373
bench (" erase(key) (existent)" , [=](auto & st) {
374
- const std::size_t size = st.range (0 );
374
+ const std::size_t size = st.range (0 ) ? st. range ( 0 ) : 1 ; // avoid empty container
375
375
std::vector<Value> in = make_value_types (generate_unique_keys (size));
376
376
Value element = in[in.size () / 2 ]; // pick any element
377
377
std::vector<Container> c (BatchSize, Container (in.begin (), in.end ()));
@@ -415,7 +415,7 @@ void associative_container_benchmarks(std::string container) {
415
415
});
416
416
417
417
bench (" erase(iterator)" , [=](auto & st) {
418
- const std::size_t size = st.range (0 );
418
+ const std::size_t size = st.range (0 ) ? st. range ( 0 ) : 1 ; // avoid empty container
419
419
std::vector<Value> in = make_value_types (generate_unique_keys (size));
420
420
Value element = in[in.size () / 2 ]; // pick any element
421
421
@@ -494,7 +494,7 @@ void associative_container_benchmarks(std::string container) {
494
494
Container c (in.begin (), in.end ());
495
495
496
496
while (st.KeepRunningBatch (BatchSize)) {
497
- for (std::size_t i = 0 ; i != BatchSize ; ++i) {
497
+ for (std::size_t i = 0 ; i != keys. size () ; ++i) { // possible empty keys when Arg(0)
498
498
auto result = func (c, keys[i]);
499
499
benchmark::DoNotOptimize (c);
500
500
benchmark::DoNotOptimize (result);
0 commit comments