GetConfigNonZeroExpected(DeletePercentage, 5);
GetConfigNonZeroExpected(ThreadCount, 4);
GetConfigNonZeroExpected(MapKeyRange, 20000);
- GetConfigNonZeroExpected(CrudeMapCapacity, s_nMapKeyRange * 64);
+ // CrudeMap may need a big enough capacity in case may insertion operations
+ // got jammed up.
+ GetConfigNonZeroExpected(CrudeMapCapacity, s_nMapKeyRange * 1024);
GetConfigNonZeroExpected(GCFrequency, 1500);
GetConfigNonZeroExpected(CrudePassCount, 1500000000);
GetConfigNonZeroExpected(GrampaPassCount, 650000000);
*inserted_num = nInsertedNum;
*deleted_num = nDeletedNum;
}
+
+ template <typename Map>
+ void JunctionThreading(Map* map, size_t pass_count) {
+ std::unique_ptr<std::thread[]> threads(new std::thread[s_nThreadCount]);
+ std::unique_ptr<size_t[]> inserted_nums(new size_t[s_nThreadCount]);
+ std::unique_ptr<size_t[]> deleted_nums(new size_t[s_nThreadCount]);
+ for (size_t i = 0; i < s_nThreadCount; i++) {
+ threads[i] = std::thread(run_test<Map>, map, pass_count,
+ &inserted_nums[i], &deleted_nums[i]);
+ }
+ size_t inserted_sum = 0;
+ size_t deleted_sum = 0;
+ for (size_t i = 0; i < s_nThreadCount; i++) {
+ threads[i].join();
+ inserted_sum += inserted_nums[i];
+ deleted_sum += deleted_nums[i];
+ }
+ EXPECT_LE(deleted_sum, inserted_sum);
+ }
};
size_t JunctionMapInsDelFindTest_Parallel::s_nThreadCount;
size_t JunctionMapInsDelFindTest_Parallel::s_nLinearPassCount;
size_t JunctionMapInsDelFindTest_Parallel::s_nLeapfrogPassCount;
-#define JunctionThreading(map_type, pass_count) \
- std::unique_ptr<std::thread[]> threads(new std::thread[s_nThreadCount]); \
- std::unique_ptr<size_t[]> inserted_nums(new size_t[s_nThreadCount]); \
- std::unique_ptr<size_t[]> deleted_nums(new size_t[s_nThreadCount]); \
- for (size_t i = 0; i < s_nThreadCount; i++) { \
- threads[i] = std::thread(run_test<map_type>, map.get(), pass_count, \
- &inserted_nums[i], &deleted_nums[i]); \
- } \
- size_t inserted_sum = 0; \
- size_t deleted_sum = 0; \
- for (size_t i = 0; i < s_nThreadCount; i++) { \
- threads[i].join(); \
- inserted_sum += inserted_nums[i]; \
- deleted_sum += deleted_nums[i]; \
- } \
- EXPECT_LE(deleted_sum, inserted_sum);
-
TEST_F(JunctionMapInsDelFindTest_Parallel, JunctionMapCrude) {
std::unique_ptr<CrudeMap> map(new CrudeMap(s_nCrudeMapCapacity));
- JunctionThreading(CrudeMap, s_nCrudePassCount);
+ JunctionThreading(map.get(), s_nCrudePassCount);
}
TEST_F(JunctionMapInsDelFindTest_Parallel, JunctionMapLeapfrog) {
std::unique_ptr<LeapfrogMap> map(new LeapfrogMap());
- JunctionThreading(LeapfrogMap, s_nLeapfrogPassCount);
+ JunctionThreading(map.get(), s_nLeapfrogPassCount);
}
TEST_F(JunctionMapInsDelFindTest_Parallel, JunctionMapLinear) {
std::unique_ptr<LinearMap> map(new LinearMap());
- JunctionThreading(LinearMap, s_nLinearPassCount);
+ JunctionThreading(map.get(), s_nLinearPassCount);
}
TEST_F(JunctionMapInsDelFindTest_Parallel, JunctionMapGrampa) {
std::unique_ptr<GrampaMap> map(new GrampaMap());
- JunctionThreading(GrampaMap, s_nGrampaPassCount);
+ JunctionThreading(map.get(), s_nGrampaPassCount);
}
} // namespace junction_test