@@ -135,6 +135,79 @@ void BM_InsertValueRehash(benchmark::State& st, Container c, GenInputs gen) {
135
135
}
136
136
}
137
137
138
+ template <class Container , class GenInputs >
139
+ void BM_insert_inputiteriter (benchmark::State& st, Container c, GenInputs gen) {
140
+ auto in = gen (st.range (0 ));
141
+ DoNotOptimizeData (in);
142
+ const auto size = c.size ();
143
+ const auto beg = cpp17_input_iterator (in.begin ());
144
+ const auto end = cpp17_input_iterator (in.end ());
145
+ for (auto _ : st) {
146
+ benchmark::DoNotOptimize (&(*c.insert (c.begin (), beg, end)));
147
+ st.PauseTiming ();
148
+ c.erase (c.begin () + size, c.end ()); // avoid the container to grow indefinitely
149
+ st.ResumeTiming ();
150
+ DoNotOptimizeData (c);
151
+ benchmark::ClobberMemory ();
152
+ }
153
+ }
154
+
155
+ template <class Container , class GenInputs >
156
+ void BM_insert_inputiteriter_empty (benchmark::State& st, Container _, GenInputs gen) {
157
+ auto in = gen (st.range (0 ));
158
+ DoNotOptimizeData (in);
159
+ const auto beg = cpp17_input_iterator (in.begin ());
160
+ const auto end = cpp17_input_iterator (in.end ());
161
+ for (auto _ : st) {
162
+ Container c; // Test with empty container
163
+ benchmark::DoNotOptimize (&(*c.insert (c.begin (), beg, end)));
164
+ DoNotOptimizeData (c);
165
+ benchmark::ClobberMemory ();
166
+ }
167
+ }
168
+
169
+ template <class Container , class GenInputs >
170
+ void BM_insert_inputiteriter_halffull (benchmark::State& st, Container _, GenInputs gen) {
171
+ const auto size = st.range (0 );
172
+ Container a = gen (size);
173
+ Container in = gen (size + 10 );
174
+ DoNotOptimizeData (a);
175
+ DoNotOptimizeData (in);
176
+ const auto beg = cpp17_input_iterator (in.begin ());
177
+ const auto end = cpp17_input_iterator (in.end ());
178
+ for (auto _ : st) {
179
+ st.PauseTiming ();
180
+ Container c;
181
+ c.reserve (size * 2 ); // Test with half-full container
182
+ c = a;
183
+ st.ResumeTiming ();
184
+ benchmark::DoNotOptimize (&(*c.insert (c.begin (), beg, end)));
185
+ DoNotOptimizeData (c);
186
+ benchmark::ClobberMemory ();
187
+ }
188
+ }
189
+
190
+ template <class Container , class GenInputs >
191
+ void BM_insert_inputiteriter_full (benchmark::State& st, Container _, GenInputs gen) {
192
+ const auto size = st.range (0 );
193
+ Container a = gen (size);
194
+ Container in = gen (10 );
195
+ DoNotOptimizeData (a);
196
+ DoNotOptimizeData (in);
197
+ const auto beg = cpp17_input_iterator (in.begin ());
198
+ const auto end = cpp17_input_iterator (in.end ());
199
+ for (auto _ : st) {
200
+ st.PauseTiming ();
201
+ Container c;
202
+ c.reserve (size + 5 ); // Test with almost-full container
203
+ c = a;
204
+ st.ResumeTiming ();
205
+ benchmark::DoNotOptimize (&(*c.insert (c.begin (), beg, end)));
206
+ DoNotOptimizeData (c);
207
+ benchmark::ClobberMemory ();
208
+ }
209
+ }
210
+
138
211
template <class Container , class GenInputs >
139
212
void BM_InsertDuplicate (benchmark::State& st, Container c, GenInputs gen) {
140
213
auto in = gen (st.range (0 ));
0 commit comments