Skip to content

Commit 004e561

Browse files
committed
Always fill with the same value
1 parent 8f05f2a commit 004e561

File tree

2 files changed

+4
-12
lines changed

2 files changed

+4
-12
lines changed

libcxx/test/benchmarks/algorithms/modifying/fill.bench.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,13 @@ int main(int argc, char** argv) {
3232
std::size_t const size = st.range(0);
3333
using ValueType = typename Container::value_type;
3434
ValueType x = Generate<ValueType>::random();
35-
ValueType y = Generate<ValueType>::random();
36-
Container c(size, y);
35+
Container c(size, x);
3736

3837
for ([[maybe_unused]] auto _ : st) {
3938
benchmark::DoNotOptimize(c);
4039
benchmark::DoNotOptimize(x);
4140
fill(c.begin(), c.end(), x);
4241
benchmark::DoNotOptimize(c);
43-
std::swap(x, y);
4442
}
4543
})
4644
->Arg(32)
@@ -61,15 +59,13 @@ int main(int argc, char** argv) {
6159
benchmark::RegisterBenchmark(name, [fill](auto& st) {
6260
std::size_t const size = st.range(0);
6361
bool x = true;
64-
bool y = false;
65-
std::vector<bool> c(size, y);
62+
std::vector<bool> c(size, x);
6663

6764
for ([[maybe_unused]] auto _ : st) {
6865
benchmark::DoNotOptimize(c);
6966
benchmark::DoNotOptimize(x);
7067
fill(c.begin(), c.end(), x);
7168
benchmark::DoNotOptimize(c);
72-
std::swap(x, y);
7369
}
7470
})->Range(64, 1 << 20);
7571
};

libcxx/test/benchmarks/algorithms/modifying/fill_n.bench.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,13 @@ int main(int argc, char** argv) {
3232
std::size_t const size = st.range(0);
3333
using ValueType = typename Container::value_type;
3434
ValueType x = Generate<ValueType>::random();
35-
ValueType y = Generate<ValueType>::random();
36-
Container c(size, y);
35+
Container c(size, x);
3736

3837
for ([[maybe_unused]] auto _ : st) {
3938
benchmark::DoNotOptimize(c);
4039
benchmark::DoNotOptimize(x);
4140
fill_n(c.begin(), size, x);
4241
benchmark::DoNotOptimize(c);
43-
std::swap(x, y);
4442
}
4543
})
4644
->Arg(32)
@@ -61,15 +59,13 @@ int main(int argc, char** argv) {
6159
benchmark::RegisterBenchmark(name, [fill_n](auto& st) {
6260
std::size_t const size = st.range(0);
6361
bool x = true;
64-
bool y = false;
65-
std::vector<bool> c(size, y);
62+
std::vector<bool> c(size, x);
6663

6764
for ([[maybe_unused]] auto _ : st) {
6865
benchmark::DoNotOptimize(c);
6966
benchmark::DoNotOptimize(x);
7067
fill_n(c.begin(), size, x);
7168
benchmark::DoNotOptimize(c);
72-
std::swap(x, y);
7369
}
7470
})->Range(64, 1 << 20);
7571
};

0 commit comments

Comments
 (0)