From e9d736e95fdeb0d50546e04501d88180ac4c9870 Mon Sep 17 00:00:00 2001 From: timerix Date: Wed, 5 Oct 2022 20:25:20 +0600 Subject: [PATCH] autoarr vs vector --- tests/main.cpp | 1 + tests/test_autoarr-vs-vector.cpp | 40 ++++++++++++++++++++++++++++++++ tests/tests.h | 2 ++ 3 files changed, 43 insertions(+) create mode 100644 tests/test_autoarr-vs-vector.cpp diff --git a/tests/main.cpp b/tests/main.cpp index 9136271..39d2405 100644 --- a/tests/main.cpp +++ b/tests/main.cpp @@ -5,6 +5,7 @@ void test_all(){ test_safethrow(); test_searchtree(); test_autoarr(); + test_autoarrVsVector(); test_hash_functions(); test_hashtable(); test_dtsod(); diff --git a/tests/test_autoarr-vs-vector.cpp b/tests/test_autoarr-vs-vector.cpp new file mode 100644 index 0000000..1468463 --- /dev/null +++ b/tests/test_autoarr-vs-vector.cpp @@ -0,0 +1,40 @@ +#include "tests.h" +#include "../src/Autoarr/Autoarr.h" +#include + +int64 _autoarrVsVector(uint16 blockCount, uint16 blockLength){ + uint32 count=blockLength*blockCount; + printf("\e[94mblock count: %u block length: %u count: %llu\n", blockCount, blockLength, (uint64)count); + Autoarr_int64* ar=Autoarr_create(int64, blockCount, blockLength); + std::vector vec=std::vector(); + optime("Autoarr_add", 1, ({ + for(uint32 i=0; i< count; i++) + Autoarr_add(ar, i); + })); + optime("vector_push_back", 1, ({ + for(uint32 i=0; i< count; i++) + vec.push_back(i); + })); + int64 t; + optime("Autoarr_get", 1, ({ + for(uint32 i=0; i< count; i++) + t=Autoarr_get(ar, i); + })); + optime("vector_get", 1, ({ + for(uint32 i=0; i< count; i++) + t=vec[i]; + })); + Autoarr_free(ar, true); + return t; +} + +void test_autoarrVsVector(){ + printf("\e[96m-------[test_autoarr_vs_vector]-------\n"); + _autoarrVsVector(4, 16); + _autoarrVsVector(16, 64); + _autoarrVsVector(32, 32); + _autoarrVsVector(64, 64); + _autoarrVsVector(32, 1024); + _autoarrVsVector(256, 256); + _autoarrVsVector(1024, 1024); +} diff --git a/tests/tests.h b/tests/tests.h index 71cc4b1..584d8c4 100644 --- a/tests/tests.h +++ b/tests/tests.h @@ -13,6 +13,8 @@ void test_autoarr(); void test_hash_functions(); void test_hashtable(); void test_dtsod(); +void test_kprint_colors(); +void test_autoarrVsVector(); #define PRINT_SIZEOF(T) printf("\e[94m" #T " size: \e[96m" IFWIN("%llu", "%lu") "\n", sizeof(T))