From: Peizhao Ou Date: Thu, 1 Feb 2018 20:05:15 +0000 (-0800) Subject: Includes all 4 types of junction map in test case X-Git-Url: http://plrg.eecs.uci.edu/git/?p=junction.git;a=commitdiff_plain;h=fbd41a64f9cf3759b0c8b1ed8c890f53848184bb Includes all 4 types of junction map in test case --- diff --git a/test/junction_driver.cpp b/test/junction_driver.cpp index 0b2fcf9..68ef214 100644 --- a/test/junction_driver.cpp +++ b/test/junction_driver.cpp @@ -1,4 +1,7 @@ #include +#include +#include +#include #include #include #include @@ -10,14 +13,84 @@ const unsigned s_nInsertPercentage = 10; const char* kTestName = "InsDelFind"; const size_t kGrampaMapSize = 20000; const size_t kGrampaPassCount = 30000; -const char* kGrampaBenchmarkName = "JunctionMapLinear"; +const char* kGrampaBenchmarkName = "JunctionMapGrampa"; + +const size_t kLinearMapSize = 25000; +const size_t kLinearPassCount = 30000; +const char* kLinearBenchmarkName = "JunctionMapLinear"; + +const size_t kLeapfrogMapSize = 25000; +const size_t kLeapfrogPassCount = 30000; +const char* kLeapfrogBenchmarkName = "JunctionMapLeapfrog"; + +const size_t kCrudeMapSize = 10000; +const size_t kCrudePassCount = 120000; +const char* kCrudeBenchmarkName = "JunctionMapCrude"; } // namespace typedef junction::ConcurrentMap_Grampa GrampaMap; +typedef junction::ConcurrentMap_Linear LinearMap; +typedef junction::ConcurrentMap_Leapfrog LeapfrogMap; +typedef junction::ConcurrentMap_Crude CrudeMap; + +template +void run_crude_map(size_t map_size, size_t pass_count, const char* bench_name) { + std::cout << "[ RUN ] " << kTestName << "." << bench_name << "\n"; + auto start_time = std::chrono::system_clock::now(); + + size_t nInsertedNum = 0; + size_t nFindSuccess = 0; + // Seems like the crude map won't resize, so better have a large enough + // capacity. + std::unique_ptr map(new Map(map_size * 32)); + auto qsbrContext = junction::DefaultQSBR.createContext(); + for (size_t count = 0; count < pass_count; count++) { + for (size_t i = 0; i < map_size; ++i) { + // The number to operate on the map. + size_t n = map_size + i; + // Insert + if (i % s_nInsertPercentage == 1) { + map->assign(i, n); + nInsertedNum++; +// std::cout << "Inserted" << i << "\n"; + } + // Find + { + if (map->get(i)) { + ++nFindSuccess; +// std::cout << "Found" << i << "\n"; + } + } + // Delete + if (i % s_nInsertPercentage == 1) { + if (map->get(i)) { + map->assign(n, 0); +// std::cout << "Erased" << i << "\n"; + } + } + junction::DefaultQSBR.update(qsbrContext); + } + } + auto finish_time = std::chrono::system_clock::now(); + auto dur = finish_time - start_time; + auto milisecs = std::chrono::duration_cast(dur); + + if (nFindSuccess != nInsertedNum) { + std::cout << "nFindSuccess=" << nFindSuccess << ", nInsertedNum=" + << nInsertedNum << "\n"; + std::cout << "[ FAILED ] " << kTestName << "." << bench_name + << "(" << milisecs.count() << " ms)\n"; + assert(false && "ConcurrentMap ERROR"); + } else { + std::cout << "[ OK ] " << kTestName << "." << bench_name + << "(" << milisecs.count() << " ms)\n"; + } +} template void run_test(size_t map_size, size_t pass_count, const char* bench_name) { + std::cout << "[ RUN ] " << kTestName << "." << bench_name << "\n"; auto start_time = std::chrono::system_clock::now(); size_t nInsertedNum = 0; @@ -30,27 +103,27 @@ void run_test(size_t map_size, size_t pass_count, const char* bench_name) { size_t n = map_size + i; // Insert if (i % s_nInsertPercentage == 1) { - auto iter = map->insertOrFind(n); + auto iter = map->insertOrFind(i); if (!iter.getValue()) { iter.assignValue(n); nInsertedNum++; -// std::cout << "Inserted" << n << "\n"; +// std::cout << "Inserted" << i << "\n"; } } // Find { - auto iter = map->find(n); + auto iter = map->find(i); if (iter.getValue()) { ++nFindSuccess; -// std::cout << "Found" << n << "\n"; +// std::cout << "Found" << i << "\n"; } } // Delete if (i % s_nInsertPercentage == 1) { - auto iter = map->find(n); + auto iter = map->find(i); if (iter.getValue()) { iter.eraseValue(); -// std::cout << "Erased" << n << "\n"; +// std::cout << "Erased" << i << "\n"; } } junction::DefaultQSBR.update(qsbrContext); @@ -73,6 +146,9 @@ void run_test(size_t map_size, size_t pass_count, const char* bench_name) { } int main() { + run_crude_map(kCrudeMapSize, kCrudePassCount, kCrudeBenchmarkName); + run_test(kLeapfrogMapSize, kLeapfrogPassCount, kLeapfrogBenchmarkName); + run_test(kLinearMapSize, kLinearPassCount, kLinearBenchmarkName); run_test(kGrampaMapSize, kGrampaPassCount, kGrampaBenchmarkName); return 0; }