[libcxx-commits] [libcxx] [libc++][test] Speed up input generating functions for benchmark tests (PR #115544)
Peng Liu via libcxx-commits
libcxx-commits at lists.llvm.org
Fri Nov 8 14:38:50 PST 2024
https://github.com/winner245 updated https://github.com/llvm/llvm-project/pull/115544
>From 6c50f6fec8bf9c26b23505686e1225ba32c36a47 Mon Sep 17 00:00:00 2001
From: Peng Liu <winner245 at hotmail.com>
Date: Fri, 8 Nov 2024 14:34:23 -0500
Subject: [PATCH] Speed up input generating functions for benchmark tests
---
libcxx/test/benchmarks/GenerateInput.h | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/libcxx/test/benchmarks/GenerateInput.h b/libcxx/test/benchmarks/GenerateInput.h
index cc1694311473ed..b6da6eb3babf09 100644
--- a/libcxx/test/benchmarks/GenerateInput.h
+++ b/libcxx/test/benchmarks/GenerateInput.h
@@ -53,6 +53,7 @@ inline std::vector<IntT> getDuplicateIntegerInputs(size_t N) {
template <class IntT>
inline std::vector<IntT> getSortedIntegerInputs(size_t N) {
std::vector<IntT> inputs;
+ inputs.reserve(N);
for (size_t i = 0; i < N; i += 1)
inputs.push_back(i);
return inputs;
@@ -61,6 +62,7 @@ inline std::vector<IntT> getSortedIntegerInputs(size_t N) {
template <class IntT>
std::vector<IntT> getSortedLargeIntegerInputs(size_t N) {
std::vector<IntT> inputs;
+ inputs.reserve(N);
for (size_t i = 0; i < N; ++i) {
inputs.push_back(i + N);
}
@@ -78,6 +80,7 @@ std::vector<IntT> getSortedTopBitsIntegerInputs(size_t N) {
template <class IntT>
inline std::vector<IntT> getReverseSortedIntegerInputs(size_t N) {
std::vector<IntT> inputs;
+ inputs.reserve(N);
std::size_t i = N;
while (i > 0) {
--i;
@@ -100,6 +103,7 @@ std::vector<IntT> getPipeOrganIntegerInputs(size_t N) {
template <class IntT>
std::vector<IntT> getRandomIntegerInputs(size_t N) {
std::vector<IntT> inputs;
+ inputs.reserve(N);
for (size_t i = 0; i < N; ++i) {
inputs.push_back(getRandomInteger<IntT>(0, std::numeric_limits<IntT>::max()));
}
@@ -113,6 +117,7 @@ inline std::vector<std::string> getDuplicateStringInputs(size_t N) {
inline std::vector<std::string> getRandomStringInputs(size_t N) {
std::vector<std::string> inputs;
+ inputs.reserve(N);
for (size_t i = 0; i < N; ++i) {
inputs.push_back(getRandomString(1024));
}
@@ -121,6 +126,7 @@ inline std::vector<std::string> getRandomStringInputs(size_t N) {
inline std::vector<std::string> getPrefixedRandomStringInputs(size_t N) {
std::vector<std::string> inputs;
+ inputs.reserve(N);
constexpr int kSuffixLength = 32;
const std::string prefix = getRandomString(1024 - kSuffixLength);
for (size_t i = 0; i < N; ++i) {
More information about the libcxx-commits
mailing list