From: Peizhao Ou Date: Thu, 1 Feb 2018 19:30:48 +0000 (-0800) Subject: Refactors test case driver X-Git-Url: http://plrg.eecs.uci.edu/git/?p=junction.git;a=commitdiff_plain;h=8033f6ca38e5a66995bf90beb1cbaff810298db4;hp=25f506461d31ae2b6c661d2dafa356a3e2c989e3;ds=sidebyside Refactors test case driver --- diff --git a/test/grampa_driver.cpp b/test/grampa_driver.cpp deleted file mode 100644 index 0b2fcf9..0000000 --- a/test/grampa_driver.cpp +++ /dev/null @@ -1,78 +0,0 @@ -#include -#include -#include -#include -#include - -namespace { - -const unsigned s_nInsertPercentage = 10; -const char* kTestName = "InsDelFind"; -const size_t kGrampaMapSize = 20000; -const size_t kGrampaPassCount = 30000; -const char* kGrampaBenchmarkName = "JunctionMapLinear"; - -} // namespace - -typedef junction::ConcurrentMap_Grampa GrampaMap; - -template -void run_test(size_t map_size, size_t pass_count, const char* bench_name) { - auto start_time = std::chrono::system_clock::now(); - - size_t nInsertedNum = 0; - size_t nFindSuccess = 0; - std::unique_ptr map(new Map()); - 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) { - auto iter = map->insertOrFind(n); - if (!iter.getValue()) { - iter.assignValue(n); - nInsertedNum++; -// std::cout << "Inserted" << n << "\n"; - } - } - // Find - { - auto iter = map->find(n); - if (iter.getValue()) { - ++nFindSuccess; -// std::cout << "Found" << n << "\n"; - } - } - // Delete - if (i % s_nInsertPercentage == 1) { - auto iter = map->find(n); - if (iter.getValue()) { - iter.eraseValue(); -// std::cout << "Erased" << n << "\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"; - } -} - -int main() { - run_test(kGrampaMapSize, kGrampaPassCount, kGrampaBenchmarkName); - return 0; -} diff --git a/test/junction_driver.cpp b/test/junction_driver.cpp new file mode 100644 index 0000000..0b2fcf9 --- /dev/null +++ b/test/junction_driver.cpp @@ -0,0 +1,78 @@ +#include +#include +#include +#include +#include + +namespace { + +const unsigned s_nInsertPercentage = 10; +const char* kTestName = "InsDelFind"; +const size_t kGrampaMapSize = 20000; +const size_t kGrampaPassCount = 30000; +const char* kGrampaBenchmarkName = "JunctionMapLinear"; + +} // namespace + +typedef junction::ConcurrentMap_Grampa GrampaMap; + +template +void run_test(size_t map_size, size_t pass_count, const char* bench_name) { + auto start_time = std::chrono::system_clock::now(); + + size_t nInsertedNum = 0; + size_t nFindSuccess = 0; + std::unique_ptr map(new Map()); + 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) { + auto iter = map->insertOrFind(n); + if (!iter.getValue()) { + iter.assignValue(n); + nInsertedNum++; +// std::cout << "Inserted" << n << "\n"; + } + } + // Find + { + auto iter = map->find(n); + if (iter.getValue()) { + ++nFindSuccess; +// std::cout << "Found" << n << "\n"; + } + } + // Delete + if (i % s_nInsertPercentage == 1) { + auto iter = map->find(n); + if (iter.getValue()) { + iter.eraseValue(); +// std::cout << "Erased" << n << "\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"; + } +} + +int main() { + run_test(kGrampaMapSize, kGrampaPassCount, kGrampaBenchmarkName); + return 0; +} diff --git a/test/linear_driver.cpp b/test/linear_driver.cpp deleted file mode 100755 index 3f8dab7..0000000 --- a/test/linear_driver.cpp +++ /dev/null @@ -1,65 +0,0 @@ -#include -#include -#include -#include -#include - -namespace { - -const size_t kMapSize = 10000; -const size_t kPassCount = 1; -const unsigned s_nInsertPercentage = 10; -const char* kTestName = "InsDelFind"; -const char* kBenchmarkName = "JunctionMapLinear"; - -} // namespace - -typedef junction::ConcurrentMap_Linear Map; - -int main() { - auto start_time = std::chrono::system_clock::now(); - - size_t nInsertedNum = 0; - size_t nFindSuccess = 0; - std::unique_ptr map(new Map(kMapSize / 8)); - for (size_t count = 0; count < kPassCount; count++) { - for (size_t i = 1; i <= kMapSize; ++i) { - // The number to operate on the map. - size_t n = i; - // Insert - if (i % s_nInsertPercentage == 1) { - auto iter = map->insertOrFind(n); - if (!iter.getValue()) { - iter.assignValue(n + 1); - nInsertedNum++; - std::cout << "Inserted\n"; - } - } - // Find - { - auto iter = map->find(n); - if (!iter.getValue()) { - ++nFindSuccess; - std::cout << "Found\n"; - } - } - // Delete - if (i % s_nInsertPercentage == 1) { - auto iter = map->find(n); - if (iter.getValue()) { - iter.eraseValue(); - std::cout << "Erased\n"; - } - } - } - } - assert(nFindSuccess == nFindSuccess && "junction::ConcurrentMap_Linear ERROR"); - - auto finish_time = std::chrono::system_clock::now(); - auto dur = finish_time - start_time; - auto milisecs = std::chrono::duration_cast(dur); - std::cout << "[ OK ] " << kTestName << "." << kBenchmarkName << "(" - << milisecs.count() << " ms)\n"; - - return 0; -}