Skip to content

Commit 658cd30

Browse files
committed
Call DoNotOptimize on the result of operations
1 parent 90b4ecd commit 658cd30

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

libcxx/test/benchmarks/containers/associative/associative_container_benchmarks.h

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,8 @@ void associative_container_benchmarks(std::string container) {
171171

172172
while (st.KeepRunningBatch(BatchSize)) {
173173
for (std::size_t i = 0; i != BatchSize; ++i) {
174-
c[i].insert(to_insert);
174+
auto result = c[i].insert(to_insert);
175+
benchmark::DoNotOptimize(result);
175176
benchmark::DoNotOptimize(c[i]);
176177
benchmark::ClobberMemory();
177178
}
@@ -199,7 +200,8 @@ void associative_container_benchmarks(std::string container) {
199200

200201
while (st.KeepRunningBatch(BatchSize)) {
201202
for (std::size_t i = 0; i != BatchSize; ++i) {
202-
c[i].insert(to_insert);
203+
auto result = c[i].insert(to_insert);
204+
benchmark::DoNotOptimize(result);
203205
benchmark::DoNotOptimize(c[i]);
204206
benchmark::ClobberMemory();
205207
}
@@ -229,7 +231,8 @@ void associative_container_benchmarks(std::string container) {
229231

230232
while (st.KeepRunningBatch(BatchSize)) {
231233
for (std::size_t i = 0; i != BatchSize; ++i) {
232-
c[i].insert(hints[i], to_insert);
234+
auto result = c[i].insert(hints[i], to_insert);
235+
benchmark::DoNotOptimize(result);
233236
benchmark::DoNotOptimize(c[i]);
234237
benchmark::ClobberMemory();
235238
}
@@ -252,7 +255,8 @@ void associative_container_benchmarks(std::string container) {
252255

253256
while (st.KeepRunningBatch(BatchSize)) {
254257
for (std::size_t i = 0; i != BatchSize; ++i) {
255-
c[i].insert(c[i].begin(), to_insert);
258+
auto result = c[i].insert(c[i].begin(), to_insert);
259+
benchmark::DoNotOptimize(result);
256260
benchmark::DoNotOptimize(c[i]);
257261
benchmark::ClobberMemory();
258262
}
@@ -323,7 +327,8 @@ void associative_container_benchmarks(std::string container) {
323327

324328
while (st.KeepRunningBatch(BatchSize)) {
325329
for (std::size_t i = 0; i != BatchSize; ++i) {
326-
c[i].erase(get_key(element));
330+
auto result = c[i].erase(get_key(element));
331+
benchmark::DoNotOptimize(result);
327332
benchmark::DoNotOptimize(c[i]);
328333
benchmark::ClobberMemory();
329334
}
@@ -345,7 +350,8 @@ void associative_container_benchmarks(std::string container) {
345350

346351
while (st.KeepRunningBatch(BatchSize)) {
347352
for (std::size_t i = 0; i != BatchSize; ++i) {
348-
c.erase(get_key(element));
353+
auto result = c.erase(get_key(element));
354+
benchmark::DoNotOptimize(result);
349355
benchmark::DoNotOptimize(c);
350356
benchmark::ClobberMemory();
351357
}
@@ -368,7 +374,8 @@ void associative_container_benchmarks(std::string container) {
368374

369375
while (st.KeepRunningBatch(BatchSize)) {
370376
for (std::size_t i = 0; i != BatchSize; ++i) {
371-
c[i].erase(iterators[i]);
377+
auto result = c[i].erase(iterators[i]);
378+
benchmark::DoNotOptimize(result);
372379
benchmark::DoNotOptimize(c[i]);
373380
benchmark::ClobberMemory();
374381
}
@@ -389,7 +396,8 @@ void associative_container_benchmarks(std::string container) {
389396
auto first = std::next(c.begin(), c.size() / 4);
390397
auto last = std::next(c.begin(), 3 * (c.size() / 4));
391398
for (auto _ : st) {
392-
c.erase(first, last);
399+
auto result = c.erase(first, last);
400+
benchmark::DoNotOptimize(result);
393401
benchmark::DoNotOptimize(c);
394402
benchmark::ClobberMemory();
395403

@@ -426,9 +434,9 @@ void associative_container_benchmarks(std::string container) {
426434
Container c(in.begin(), in.end());
427435

428436
for (auto _ : st) {
429-
auto res = c.size();
437+
auto result = c.size();
438+
benchmark::DoNotOptimize(result);
430439
benchmark::DoNotOptimize(c);
431-
benchmark::DoNotOptimize(res);
432440
benchmark::ClobberMemory();
433441
}
434442
});

0 commit comments

Comments
 (0)