autoarr vs vector

This commit is contained in:
timerix 2022-10-05 20:25:20 +06:00
parent 3b00d60907
commit e9d736e95f
3 changed files with 43 additions and 0 deletions

View File

@ -5,6 +5,7 @@ void test_all(){
test_safethrow();
test_searchtree();
test_autoarr();
test_autoarrVsVector();
test_hash_functions();
test_hashtable();
test_dtsod();

View File

@ -0,0 +1,40 @@
#include "tests.h"
#include "../src/Autoarr/Autoarr.h"
#include <vector>
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<int64> vec=std::vector<int64>();
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);
}

View File

@ -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))