Skip to content

Commit c355ebe

Browse files
committed
Ensure uniqueness of elements when needed
1 parent 285e315 commit c355ebe

File tree

11 files changed

+33
-24
lines changed

11 files changed

+33
-24
lines changed

libcxx/test/benchmarks/GenerateInput.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,4 +204,13 @@ struct Generate<std::string> {
204204
}
205205
};
206206

207+
template <class T>
208+
T random_different_from(std::initializer_list<T> others) {
209+
T value;
210+
do {
211+
value = Generate<T>::random();
212+
} while (std::ranges::contains(others, value));
213+
return value;
214+
}
215+
207216
#endif // BENCHMARK_GENERATE_INPUT_H

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ int main(int argc, char** argv) {
3737
using ValueType = typename Container::value_type;
3838
Container c[BatchSize];
3939
ValueType x = Generate<ValueType>::random();
40-
ValueType y = Generate<ValueType>::random();
40+
ValueType y = random_different_from({x});
4141
for (std::size_t i = 0; i != BatchSize; ++i) {
4242
c[i] = Container(size);
4343
auto half = size / 2;
@@ -87,7 +87,7 @@ int main(int argc, char** argv) {
8787
using ValueType = typename Container::value_type;
8888
Container c[BatchSize];
8989
ValueType x = Generate<ValueType>::random();
90-
ValueType y = Generate<ValueType>::random();
90+
ValueType y = random_different_from({x});
9191
auto alternate = [&](auto out, auto n) {
9292
for (std::size_t i = 0; i != n; ++i) {
9393
*out++ = (i % 2 == 0 ? x : y);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ int main(int argc, char** argv) {
3535
using ValueType = typename Container::value_type;
3636
Container c;
3737
ValueType x = Generate<ValueType>::random();
38-
ValueType y = Generate<ValueType>::random();
38+
ValueType y = random_different_from({x});
3939
std::fill_n(std::back_inserter(c), size / 2, x);
4040
std::fill_n(std::back_inserter(c), size / 2, y);
4141

@@ -72,7 +72,7 @@ int main(int argc, char** argv) {
7272
using ValueType = typename Container::value_type;
7373
Container c;
7474
ValueType x = Generate<ValueType>::random();
75-
ValueType y = Generate<ValueType>::random();
75+
ValueType y = random_different_from({x});
7676
for (std::size_t i = 0; i != size; ++i) {
7777
c.push_back(i % 2 == 0 ? x : y);
7878
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ int main(int argc, char** argv) {
3535
using ValueType = typename Container::value_type;
3636
Container c;
3737
ValueType x = Generate<ValueType>::random();
38-
ValueType y = Generate<ValueType>::random();
38+
ValueType y = random_different_from({x});
3939
std::fill_n(std::back_inserter(c), size / 2, x);
4040
std::fill_n(std::back_inserter(c), size / 2, y);
4141

@@ -75,7 +75,7 @@ int main(int argc, char** argv) {
7575
using ValueType = typename Container::value_type;
7676
Container c;
7777
ValueType x = Generate<ValueType>::random();
78-
ValueType y = Generate<ValueType>::random();
78+
ValueType y = random_different_from({x});
7979
for (std::size_t i = 0; i != size; ++i) {
8080
c.push_back(i % 2 == 0 ? x : y);
8181
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ int main(int argc, char** argv) {
3737
using ValueType = typename Container::value_type;
3838
Container c[BatchSize];
3939
ValueType x = Generate<ValueType>::random();
40-
ValueType y = Generate<ValueType>::random();
40+
ValueType y = random_different_from({x});
4141
for (std::size_t i = 0; i != BatchSize; ++i) {
4242
c[i] = Container(size);
4343
auto half = size / 2;
@@ -91,7 +91,7 @@ int main(int argc, char** argv) {
9191
using ValueType = typename Container::value_type;
9292
Container c[BatchSize];
9393
ValueType x = Generate<ValueType>::random();
94-
ValueType y = Generate<ValueType>::random();
94+
ValueType y = random_different_from({x});
9595
auto alternate = [&](auto out, auto n) {
9696
for (std::size_t i = 0; i != n; ++i) {
9797
*out++ = (i % 2 == 0 ? x : y);

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ int main(int argc, char** argv) {
3636
using ValueType = typename Container::value_type;
3737
Container c;
3838
ValueType x = Generate<ValueType>::random();
39-
ValueType y = Generate<ValueType>::random();
40-
ValueType z = Generate<ValueType>::random();
39+
ValueType y = random_different_from({x});
40+
ValueType z = random_different_from({x, y});
4141
std::fill_n(std::back_inserter(c), size / 2, x);
4242
std::fill_n(std::back_inserter(c), size / 2, y);
4343

@@ -72,8 +72,8 @@ int main(int argc, char** argv) {
7272
using ValueType = typename Container::value_type;
7373
Container c;
7474
ValueType x = Generate<ValueType>::random();
75-
ValueType y = Generate<ValueType>::random();
76-
ValueType z = Generate<ValueType>::random();
75+
ValueType y = random_different_from({x});
76+
ValueType z = random_different_from({x, y});
7777
for (std::size_t i = 0; i != size; ++i) {
7878
c.push_back(i % 2 == 0 ? x : y);
7979
}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ int main(int argc, char** argv) {
3838
using ValueType = typename Container::value_type;
3939
Container c;
4040
ValueType x = Generate<ValueType>::random();
41-
ValueType y = Generate<ValueType>::random();
42-
ValueType z = Generate<ValueType>::random();
41+
ValueType y = random_different_from({x});
42+
ValueType z = random_different_from({x, y});
4343
std::fill_n(std::back_inserter(c), size / 2, x);
4444
std::fill_n(std::back_inserter(c), size / 2, y);
4545

@@ -77,8 +77,8 @@ int main(int argc, char** argv) {
7777
using ValueType = typename Container::value_type;
7878
Container c;
7979
ValueType x = Generate<ValueType>::random();
80-
ValueType y = Generate<ValueType>::random();
81-
ValueType z = Generate<ValueType>::random();
80+
ValueType y = random_different_from({x});
81+
ValueType z = random_different_from({x, y});
8282
for (std::size_t i = 0; i != size; ++i) {
8383
c.push_back(i % 2 == 0 ? x : y);
8484
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ int main(int argc, char** argv) {
3737
using ValueType = typename Container::value_type;
3838
Container c[BatchSize];
3939
ValueType x = Generate<ValueType>::random();
40-
ValueType y = Generate<ValueType>::random();
40+
ValueType y = random_different_from({x});
4141
for (std::size_t i = 0; i != BatchSize; ++i) {
4242
c[i] = Container(size);
4343
auto half = size / 2;
@@ -86,7 +86,7 @@ int main(int argc, char** argv) {
8686
using ValueType = typename Container::value_type;
8787
Container c[BatchSize];
8888
ValueType x = Generate<ValueType>::random();
89-
ValueType y = Generate<ValueType>::random();
89+
ValueType y = random_different_from({x});
9090
auto alternate = [&](auto out, auto n) {
9191
for (std::size_t i = 0; i != n; i += 2) {
9292
*out++ = (i % 4 == 0 ? x : y);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ int main(int argc, char** argv) {
3333
using ValueType = typename Container::value_type;
3434
Container c(size);
3535
ValueType x = Generate<ValueType>::random();
36-
ValueType y = Generate<ValueType>::random();
36+
ValueType y = random_different_from({x});
3737
auto half = size / 2;
3838
std::fill_n(std::fill_n(c.begin(), half, x), half, y);
3939

@@ -69,7 +69,7 @@ int main(int argc, char** argv) {
6969
using ValueType = typename Container::value_type;
7070
Container c(size);
7171
ValueType x = Generate<ValueType>::random();
72-
ValueType y = Generate<ValueType>::random();
72+
ValueType y = random_different_from({x});
7373
auto alternate = [&](auto out, auto n) {
7474
for (std::size_t i = 0; i != n; i += 2) {
7575
*out++ = (i % 4 == 0 ? x : y);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ int main(int argc, char** argv) {
3535
using ValueType = typename Container::value_type;
3636
Container c(size);
3737
ValueType x = Generate<ValueType>::random();
38-
ValueType y = Generate<ValueType>::random();
38+
ValueType y = random_different_from({x});
3939
auto half = size / 2;
4040
std::fill_n(std::fill_n(c.begin(), half, x), half, y);
4141

@@ -77,7 +77,7 @@ int main(int argc, char** argv) {
7777
using ValueType = typename Container::value_type;
7878
Container c(size);
7979
ValueType x = Generate<ValueType>::random();
80-
ValueType y = Generate<ValueType>::random();
80+
ValueType y = random_different_from({x});
8181
auto alternate = [&](auto out, auto n) {
8282
for (std::size_t i = 0; i != n; i += 2) {
8383
*out++ = (i % 4 == 0 ? x : y);

0 commit comments

Comments
 (0)