Commit 6db47e87 authored by Shahzad Lone's avatar Shahzad Lone Committed by Facebook Github Bot

Reserve the vectors in ConcurrentHashMapTest (#998)

Summary:
Even though this is a test, we are still reallocating a vector (resizing until re-sized/reallocated to 32), which in theory calls for allocation 5 times. But we can save this by just reserving the vector pre-hand (we know the size).
Pull Request resolved: https://github.com/facebook/folly/pull/998

Reviewed By: magedm

Differential Revision: D13834292

Pulled By: yfeldblum

fbshipit-source-id: 6b0d16ef0200184d10ba292a0b1d8d3afdadf56d
parent 7ad42542
...@@ -342,6 +342,7 @@ TEST(ConcurrentHashMap, UpdateStressTest) { ...@@ -342,6 +342,7 @@ TEST(ConcurrentHashMap, UpdateStressTest) {
} }
std::vector<std::thread> threads; std::vector<std::thread> threads;
unsigned int num_threads = 32; unsigned int num_threads = 32;
threads.reserve(num_threads);
for (uint32_t t = 0; t < num_threads; t++) { for (uint32_t t = 0; t < num_threads; t++) {
threads.push_back(lib::thread([&, t]() { threads.push_back(lib::thread([&, t]() {
int offset = (iters * t / num_threads); int offset = (iters * t / num_threads);
...@@ -394,6 +395,7 @@ TEST(ConcurrentHashMap, EraseStressTest) { ...@@ -394,6 +395,7 @@ TEST(ConcurrentHashMap, EraseStressTest) {
} }
std::vector<std::thread> threads; std::vector<std::thread> threads;
unsigned int num_threads = 32; unsigned int num_threads = 32;
threads.reserve(num_threads);
for (uint32_t t = 0; t < num_threads; t++) { for (uint32_t t = 0; t < num_threads; t++) {
threads.push_back(lib::thread([&, t]() { threads.push_back(lib::thread([&, t]() {
int offset = (iters * t / num_threads); int offset = (iters * t / num_threads);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment