diff --git a/tests.sh b/tests.sh index 2b61989..c5dc507 100755 --- a/tests.sh +++ b/tests.sh @@ -6,8 +6,14 @@ g++ -pthread -Iinclude -std=c++17 -O3 -g tests/test01.cpp g++ -pthread -Iinclude -std=c++17 -O3 -g tests/test02.cpp ./a.out || echo "FAILURE ON TEST02" -g++ -pthread -Iinclude -std=c++17 -O0 -g tests/test03.cpp +g++ -pthread -Iinclude -std=c++17 -O3 -g tests/test03.cpp ./a.out || echo "FAILURE ON TEST03" -g++ -pthread -Iinclude -std=c++17 -O0 -g tests/test04.cpp -./a.out || echo "FAILURE ON TEST04" \ No newline at end of file +g++ -pthread -Iinclude -std=c++17 -O3 -g tests/test04.cpp +./a.out || echo "FAILURE ON TEST04" + +g++ -pthread -Iinclude -std=c++17 -O3 -g tests/test05.cpp +./a.out || echo "FAILURE ON TEST05" + +g++ -pthread -Iinclude -std=c++17 -O3 -g tests/test06.cpp +./a.out || echo "FAILURE ON TEST06" \ No newline at end of file diff --git a/tests/test05.cpp b/tests/test05.cpp new file mode 100644 index 0000000..eb742d0 --- /dev/null +++ b/tests/test05.cpp @@ -0,0 +1,44 @@ +#include "lfhmap.hpp" +#include +#include +#include +#include + +template +void repeat(size_t nb, fn v) { + while(nb--) { + v(); + } +} + +int main() { + constexpr size_t thread_cnt = 16; + size_t v = 0; + auto map = new mct20::lfhmap(); + std::vector> finals; + repeat(thread_cnt, [&](){ + size_t v2 = v; + v++; + finals.push_back(std::async(std::launch::async, [&map, v2](){ + for(int a = v2; a < 250000; a+=thread_cnt) { + map->set(a, std::to_string(a)); + } + for(int a = v2; a < 250000; a+=thread_cnt) { + if(auto acc = map->get(a); acc) { + const std::string& t = acc.value(); + if(t != std::to_string(a)) + return 1; + } else + return 1; + } + return 0; + })); + }); + + for(auto& a : finals) a.wait(); + int ret = 0; + for(auto& a : finals) ret += a.get(); + + + return ret; +} \ No newline at end of file diff --git a/tests/test06.cpp b/tests/test06.cpp new file mode 100644 index 0000000..3b278fc --- /dev/null +++ b/tests/test06.cpp @@ -0,0 +1,48 @@ +#include "lfhmap.hpp" +#include +#include +#include +#include + +template +void repeat(size_t nb, fn v) { + while(nb--) { + v(); + } +} + +int main() { + constexpr size_t thread_cnt = 16; + size_t v = 0; + auto map = new mct20::lfhmap(); + std::vector> finals; + auto start = std::chrono::high_resolution_clock::now(); + repeat(thread_cnt, [&](){ + size_t v2 = v; + v++; + finals.push_back(std::async(std::launch::async, [&map, v2](){ + for(int a = v2; a < 250000; a+=thread_cnt) { + map->set(a, std::to_string(a)); + } + for(int a = v2; a < 250000; a+=thread_cnt) { + if(auto acc = map->get(a); acc) { + const std::string& t = acc.value(); + if(t != std::to_string(a)) + return 1; + } else + return 1; + } + return 0; + })); + }); + + for(auto& a : finals) a.wait(); + int ret = 0; + for(auto& a : finals) ret += a.get(); + + auto time = std::chrono::high_resolution_clock::now() - start; + std::cout << "Test 06 took " << std::chrono::duration_cast(time).count() << "ms" << std::endl; + std::cout << "Per 1R1W ("<< thread_cnt << " threads) " << std::chrono::duration_cast(time).count()/250000 << "ns" << std::endl; + + return ret; +} \ No newline at end of file