-
Notifications
You must be signed in to change notification settings - Fork 12k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[libc++][test] Clean up code in GenerateInput.h for benchmark testing #115560
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
llvmbot
added
the
libc++
libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.
label
Nov 8, 2024
@llvm/pr-subscribers-libcxx Author: Peng Liu (winner245) ChangesThis PR refines the code in
Full diff: https://github.com/llvm/llvm-project/pull/115560.diff 1 Files Affected:
diff --git a/libcxx/test/benchmarks/GenerateInput.h b/libcxx/test/benchmarks/GenerateInput.h
index cc1694311473ed..0f3e9309271bb1 100644
--- a/libcxx/test/benchmarks/GenerateInput.h
+++ b/libcxx/test/benchmarks/GenerateInput.h
@@ -45,30 +45,29 @@ inline std::string getRandomString(std::size_t Len) {
}
template <class IntT>
-inline std::vector<IntT> getDuplicateIntegerInputs(size_t N) {
+inline std::vector<IntT> getDuplicateIntegerInputs(std::size_t N) {
std::vector<IntT> inputs(N, static_cast<IntT>(-1));
return inputs;
}
template <class IntT>
-inline std::vector<IntT> getSortedIntegerInputs(size_t N) {
+inline std::vector<IntT> getSortedIntegerInputs(std::size_t N) {
std::vector<IntT> inputs;
- for (size_t i = 0; i < N; i += 1)
+ for (std::size_t i = 0; i < N; i += 1)
inputs.push_back(i);
return inputs;
}
template <class IntT>
-std::vector<IntT> getSortedLargeIntegerInputs(size_t N) {
+std::vector<IntT> getSortedLargeIntegerInputs(std::size_t N) {
std::vector<IntT> inputs;
- for (size_t i = 0; i < N; ++i) {
+ for (std::size_t i = 0; i < N; ++i)
inputs.push_back(i + N);
- }
return inputs;
}
template <class IntT>
-std::vector<IntT> getSortedTopBitsIntegerInputs(size_t N) {
+std::vector<IntT> getSortedTopBitsIntegerInputs(std::size_t N) {
std::vector<IntT> inputs = getSortedIntegerInputs<IntT>(N);
for (auto& E : inputs)
E <<= ((sizeof(IntT) / 2) * CHAR_BIT);
@@ -76,7 +75,7 @@ std::vector<IntT> getSortedTopBitsIntegerInputs(size_t N) {
}
template <class IntT>
-inline std::vector<IntT> getReverseSortedIntegerInputs(size_t N) {
+inline std::vector<IntT> getReverseSortedIntegerInputs(std::size_t N) {
std::vector<IntT> inputs;
std::size_t i = N;
while (i > 0) {
@@ -87,61 +86,58 @@ inline std::vector<IntT> getReverseSortedIntegerInputs(size_t N) {
}
template <class IntT>
-std::vector<IntT> getPipeOrganIntegerInputs(size_t N) {
+std::vector<IntT> getPipeOrganIntegerInputs(std::size_t N) {
std::vector<IntT> v;
v.reserve(N);
- for (size_t i = 0; i < N / 2; ++i)
+ for (std::size_t i = 0; i < N / 2; ++i)
v.push_back(i);
- for (size_t i = N / 2; i < N; ++i)
+ for (std::size_t i = N / 2; i < N; ++i)
v.push_back(N - i);
return v;
}
template <class IntT>
-std::vector<IntT> getRandomIntegerInputs(size_t N) {
+std::vector<IntT> getRandomIntegerInputs(std::size_t N) {
std::vector<IntT> inputs;
- for (size_t i = 0; i < N; ++i) {
+ for (std::size_t i = 0; i < N; ++i)
inputs.push_back(getRandomInteger<IntT>(0, std::numeric_limits<IntT>::max()));
- }
return inputs;
}
-inline std::vector<std::string> getDuplicateStringInputs(size_t N) {
+inline std::vector<std::string> getDuplicateStringInputs(std::size_t N) {
std::vector<std::string> inputs(N, getRandomString(1024));
return inputs;
}
-inline std::vector<std::string> getRandomStringInputs(size_t N) {
+inline std::vector<std::string> getRandomStringInputs(std::size_t N) {
std::vector<std::string> inputs;
- for (size_t i = 0; i < N; ++i) {
+ for (std::size_t i = 0; i < N; ++i)
inputs.push_back(getRandomString(1024));
- }
return inputs;
}
-inline std::vector<std::string> getPrefixedRandomStringInputs(size_t N) {
+inline std::vector<std::string> getPrefixedRandomStringInputs(std::size_t N) {
std::vector<std::string> inputs;
constexpr int kSuffixLength = 32;
const std::string prefix = getRandomString(1024 - kSuffixLength);
- for (size_t i = 0; i < N; ++i) {
+ for (std::size_t i = 0; i < N; ++i)
inputs.push_back(prefix + getRandomString(kSuffixLength));
- }
return inputs;
}
-inline std::vector<std::string> getSortedStringInputs(size_t N) {
+inline std::vector<std::string> getSortedStringInputs(std::size_t N) {
std::vector<std::string> inputs = getRandomStringInputs(N);
std::sort(inputs.begin(), inputs.end());
return inputs;
}
-inline std::vector<std::string> getReverseSortedStringInputs(size_t N) {
+inline std::vector<std::string> getReverseSortedStringInputs(std::size_t N) {
std::vector<std::string> inputs = getSortedStringInputs(N);
std::reverse(inputs.begin(), inputs.end());
return inputs;
}
-inline std::vector<const char*> getRandomCStringInputs(size_t N) {
+inline std::vector<const char*> getRandomCStringInputs(std::size_t N) {
static std::vector<std::string> inputs = getRandomStringInputs(N);
std::vector<const char*> cinputs;
for (auto const& str : inputs)
|
ldionne
approved these changes
Nov 11, 2024
LGTM. The CI failures are seemingly things that were broken on |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR refines the code in
GenerateInput.h
used for benchmark testing by implementing the following changes:size_t
withstd::size_t
.{}
from for loops that contain simple single-statement bodies, in accordance with LLVM coding standards.