From eb10a4c494d95e7c17ddc44ef35197d08f2f6b33 Mon Sep 17 00:00:00 2001 From: "A. Unique TensorFlower" Date: Thu, 1 Jun 2017 09:42:04 -0700 Subject: Preallocate vector storage when the ultimate vector size is known in advance PiperOrigin-RevId: 157724431 --- tensorflow/contrib/batching/kernels/batch_kernels.cc | 1 + tensorflow/contrib/batching/shared_batch_scheduler_test.cc | 1 + 2 files changed, 2 insertions(+) (limited to 'tensorflow/contrib/batching') diff --git a/tensorflow/contrib/batching/kernels/batch_kernels.cc b/tensorflow/contrib/batching/kernels/batch_kernels.cc index 1e0957298b..3c06325651 100644 --- a/tensorflow/contrib/batching/kernels/batch_kernels.cc +++ b/tensorflow/contrib/batching/kernels/batch_kernels.cc @@ -347,6 +347,7 @@ class BatchResource : public ResourceBase { // Concatenate the tasks ith input tensors into a big output tensor. std::vector to_concatenate; + to_concatenate.reserve(batch->num_tasks()); for (int task_idx = 0; task_idx < batch->num_tasks(); ++task_idx) { to_concatenate.push_back(batch->task(task_idx).inputs.at(i)); } diff --git a/tensorflow/contrib/batching/shared_batch_scheduler_test.cc b/tensorflow/contrib/batching/shared_batch_scheduler_test.cc index 809958c737..3e924ae5f1 100644 --- a/tensorflow/contrib/batching/shared_batch_scheduler_test.cc +++ b/tensorflow/contrib/batching/shared_batch_scheduler_test.cc @@ -139,6 +139,7 @@ TEST(SharedBatchSchedulerTest, ObeyBatchSizeConstraint) { &callback_data](std::unique_ptr> batch) { ASSERT_TRUE(batch->IsClosed()); std::vector batch_data; + batch_data.reserve(batch->num_tasks()); for (int i = 0; i < batch->num_tasks(); ++i) { batch_data.push_back(batch->mutable_task(i)->size()); } -- cgit v1.2.3