From 48243fc350dfeb1363d5b7b1cc74b4c080a435ad Mon Sep 17 00:00:00 2001 From: hyzboy Date: Fri, 25 Apr 2025 00:21:16 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0List=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CMakeLists.txt | 1 + datatype/collection/ListTest.cpp | 163 +++++++++++++++++++++++++++++++ 2 files changed, 164 insertions(+) create mode 100644 datatype/collection/ListTest.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 729ce5c..6e403ca 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -65,6 +65,7 @@ cm_example_project("DataType/Collection" DataArrayTest datatype/collection/Dat cm_example_project("DataType/Collection" StackTest datatype/collection/StackTest.cpp) cm_example_project("DataType/Collection" QueueTest datatype/collection/QueueTest.cpp) cm_example_project("DataType/Collection" PoolTest datatype/collection/PoolTest.cpp) +cm_example_project("DataType/Collection" ListTest datatype/collection/ListTest.cpp) cm_example_project("DataType/Collection" MapTest datatype/collection/MapTest.cpp) cm_example_project("DataType/Collection" MultiMapTest datatype/collection/MultiMapTest.cpp) cm_example_project("DataType/Collection" StackPoolTest datatype/collection/StackPoolTest.cpp) diff --git a/datatype/collection/ListTest.cpp b/datatype/collection/ListTest.cpp new file mode 100644 index 0000000..78190f6 --- /dev/null +++ b/datatype/collection/ListTest.cpp @@ -0,0 +1,163 @@ +#include +#include +#include +#include +#include +#include + +using namespace hgl; + +constexpr const uint MAX_LIST_COUNT=1000000; +constexpr const uint DELETE_COUNT=MAX_LIST_COUNT/10; + +template +void out_list(const T &list) +{ + std::cout<<"List("<0) + std::cout<<","; + + std::cout< +void TestListType(bool pre_alloc) +{ + double start,end; + + std::random_device device; + std::mt19937 generator(device()); + + ArrayList al; + IndexedList il; + + double ar,ir; + + if(pre_alloc) + { + al.PreAlloc(MAX_LIST_COUNT); + il.PreAlloc(MAX_LIST_COUNT); + } + + AutoDeleteArray origin_data(MAX_LIST_COUNT); + AutoDeleteArray delete_index(DELETE_COUNT); + + std::cout<<"Type: "<(pre_alloc); + TestListType(pre_alloc); + TestListType(pre_alloc); + TestListType(pre_alloc); + TestListType(pre_alloc); + TestListType(pre_alloc); + TestListType(pre_alloc); + TestListType(pre_alloc); + TestListType(pre_alloc); + TestListType(pre_alloc); +} + +int main(int,char **argv) +{ + std::cout<<"No pre-alloc"<