diff --git a/Containers/CMakeLists.txt b/Containers/CMakeLists.txt index 2b17561..9b0f308 100644 --- a/Containers/CMakeLists.txt +++ b/Containers/CMakeLists.txt @@ -9,7 +9,20 @@ target_include_directories(${PROJECT_NAME} PUBLIC ./private/) target_link_libraries(${PROJECT_NAME} PUBLIC Modules) ### -------------------------- Tests -------------------------- ### -file(GLOB TEST_SOURCES "./tests/*.cpp") +file(GLOB TEST_SOURCES + ./tests/Buffer2DTest.cpp + ./tests/BufferTest.cpp + ./tests/IntervalTreeTests.cpp + ./tests/ListTest.cpp + ./tests/MapTest.cpp + ./tests/TreeTest.cpp + ./tests/Tests.cpp +) + add_executable(Tests${PROJECT_NAME} ${TEST_SOURCES}) target_link_libraries(Tests${PROJECT_NAME} ${PROJECT_NAME} UnitTest++) -add_test(NAME Tests${PROJECT_NAME} COMMAND Tests${PROJECT_NAME}) \ No newline at end of file +add_test(NAME Tests${PROJECT_NAME} COMMAND Tests${PROJECT_NAME}) + + +add_executable(AVLTreeSpeedTest ./tests/AVLTreeProfiling.cpp) +target_link_libraries(AVLTreeSpeedTest ${PROJECT_NAME}) \ No newline at end of file diff --git a/Containers/tests/AVLTreeProfiling.cpp b/Containers/tests/AVLTreeProfiling.cpp new file mode 100644 index 0000000..66532ce --- /dev/null +++ b/Containers/tests/AVLTreeProfiling.cpp @@ -0,0 +1,59 @@ +#include +#include "Tree.hpp" +#include "Timing.hpp" + +using namespace tp; + +struct Item { + Item() : + data(0) {} + bool presents = false; + alni data; +}; + +const auto size = 1000000; +Item buff[size]; + +int main() { + AvlTree, alni> tree; + + for (auto i : Range(size)) { + buff[i].data = i; + } + + Timer insertTime; + + ualni loadSize = 0; + while (loadSize < size / 2) { + auto idx = ualni(randomFloat() * (size - 1)); + if (!buff[idx].presents) { + tree.insert((alni) buff[idx].data, buff[idx].data); + loadSize++; + buff[idx].presents = true; + } + } + + std::cout << "AVL Tree Insert Speed " << (double) loadSize / (double) insertTime.timePassed() << "\n"; + + Timer removeTime; + + ualni unloadSize = 0; + while (unloadSize < size / 2) { + auto idx = ualni(randomFloat() * (size - 1)); + if (buff[idx].presents) { + tree.remove((alni) buff[idx].data); + unloadSize++; + buff[idx].presents = false; + } + } + + for (auto& item : buff) { + if (item.presents) { + tree.remove((alni) item.data); + unloadSize++; + item.presents = false; + } + } + + std::cout << "AVL Tree Remove Speed " << (double) unloadSize / (double) removeTime.timePassed() << "\n"; +} \ No newline at end of file diff --git a/Containers/tests/TreeTest.cpp b/Containers/tests/TreeTest.cpp index 353bcf8..8d726ad 100644 --- a/Containers/tests/TreeTest.cpp +++ b/Containers/tests/TreeTest.cpp @@ -124,62 +124,4 @@ SUITE(AvlTree) { CHECK(tree.maxNode(tree.head()) == nullptr); CHECK(tree.minNode(tree.head()) == nullptr); } - - TEST(Speed) { - AvlTree, TestClass, TestAllocator> tree; - - const auto size = 1000000; - - struct Item { - Item() : - data(0) {} - bool presents = false; - TestClass data; - }; - - Item* buff = new Item[size]; - - for (auto i : Range(size)) { - buff[i].data.setVal(i); - } - - Timer insertTime; - - ualni loadSize = 0; - while (loadSize < size / 2) { - auto idx = ualni(randomFloat() * (size - 1)); - if (!buff[idx].presents) { - tree.insert((alni) buff[idx].data.getVal(), buff[idx].data); - loadSize++; - buff[idx].presents = true; - } - } - - std::cout << "AVL Tree Insert Speed " << (double) loadSize / (double) insertTime.timePassed() << "\n"; - - Timer removeTime; - - ualni unloadSize = 0; - while (unloadSize < size / 2) { - auto idx = ualni(randomFloat() * (size - 1)); - if (buff[idx].presents) { - tree.remove((alni) buff[idx].data.getVal()); - unloadSize++; - buff[idx].presents = false; - } - } - - for (auto idx = 0; idx < size; idx++) { - auto& item = buff[idx]; - if (item.presents) { - tree.remove((alni) item.data.getVal()); - unloadSize++; - item.presents = false; - } - } - - std::cout << "AVL Tree Remove Speed " << (double) unloadSize / (double) removeTime.timePassed() << "\n"; - - delete[] buff; - } } \ No newline at end of file