[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
Mon Nov 11 08:24:53 PST 2024
https://github.com/winner245 updated https://github.com/llvm/llvm-project/pull/115544
>From 2046f4a6ed56f1ca3b12a226b2cdca1514cea0c5 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 0f3e9309271bb1..db376614382bc4 100644
--- a/libcxx/test/benchmarks/GenerateInput.h
+++ b/libcxx/test/benchmarks/GenerateInput.h
@@ -53,6 +53,7 @@ inline std::vector<IntT> getDuplicateIntegerInputs(std::size_t N) {
template <class IntT>
inline std::vector<IntT> getSortedIntegerInputs(std::size_t N) {
std::vector<IntT> inputs;
+ inputs.reserve(N);
for (std::size_t i = 0; i < N; i += 1)
inputs.push_back(i);
return inputs;
@@ -61,6 +62,7 @@ inline std::vector<IntT> getSortedIntegerInputs(std::size_t N) {
template <class IntT>
std::vector<IntT> getSortedLargeIntegerInputs(std::size_t N) {
std::vector<IntT> inputs;
+ inputs.reserve(N);
for (std::size_t i = 0; i < N; ++i)
inputs.push_back(i + N);
return inputs;
@@ -77,6 +79,7 @@ std::vector<IntT> getSortedTopBitsIntegerInputs(std::size_t N) {
template <class IntT>
inline std::vector<IntT> getReverseSortedIntegerInputs(std::size_t N) {
std::vector<IntT> inputs;
+ inputs.reserve(N);
std::size_t i = N;
while (i > 0) {
--i;
@@ -99,6 +102,7 @@ std::vector<IntT> getPipeOrganIntegerInputs(std::size_t N) {
template <class IntT>
std::vector<IntT> getRandomIntegerInputs(std::size_t N) {
std::vector<IntT> inputs;
+ inputs.reserve(N);
for (std::size_t i = 0; i < N; ++i)
inputs.push_back(getRandomInteger<IntT>(0, std::numeric_limits<IntT>::max()));
return inputs;
@@ -111,6 +115,7 @@ inline std::vector<std::string> getDuplicateStringInputs(std::size_t N) {
inline std::vector<std::string> getRandomStringInputs(std::size_t N) {
std::vector<std::string> inputs;
+ inputs.reserve(N);
for (std::size_t i = 0; i < N; ++i)
inputs.push_back(getRandomString(1024));
return inputs;
@@ -118,6 +123,7 @@ inline std::vector<std::string> getRandomStringInputs(std::size_t N) {
inline std::vector<std::string> getPrefixedRandomStringInputs(std::size_t N) {
std::vector<std::string> inputs;
+ inputs.reserve(N);
constexpr int kSuffixLength = 32;
const std::string prefix = getRandomString(1024 - kSuffixLength);
for (std::size_t i = 0; i < N; ++i)
More information about the libcxx-commits
mailing list