diff options
author | 2017-06-01 09:42:04 -0700 | |
---|---|---|
committer | 2017-06-01 09:45:21 -0700 | |
commit | eb10a4c494d95e7c17ddc44ef35197d08f2f6b33 (patch) | |
tree | c920e61142ba74b437c3c39036a4748ba575b039 /tensorflow/contrib/batching | |
parent | ce32228c49e595f966485acee947131e4ab04905 (diff) |
Preallocate vector storage when the ultimate vector size is known in advance
PiperOrigin-RevId: 157724431
Diffstat (limited to 'tensorflow/contrib/batching')
-rw-r--r-- | tensorflow/contrib/batching/kernels/batch_kernels.cc | 1 | ||||
-rw-r--r-- | tensorflow/contrib/batching/shared_batch_scheduler_test.cc | 1 |
2 files changed, 2 insertions, 0 deletions
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<Tensor> 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<FakeTask>> batch) { ASSERT_TRUE(batch->IsClosed()); std::vector<size_t> 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()); } |