test_hash_functions

This commit is contained in:
Timerix22 2022-06-03 20:51:57 +03:00
parent 11875856c2
commit d525270443
3 changed files with 20 additions and 20 deletions

View File

@ -1,14 +1,14 @@
#include "tests.h" #include "tests.h"
void test_all(){ void test_all(){
// test_autoarr(); test_autoarr();
// test_string(); test_string();
// test_safethrow(); test_safethrow();
// test_searchtree(); test_searchtree();
// test_hashtable(); test_hashtable();
// test_dtsod(); test_dtsod();
// test_autoarr2(); test_autoarr2();
test_hash_collisions(); test_hash_functions();
printf("\e[96m---------------------------------------\e[0m\n"); printf("\e[96m---------------------------------------\e[0m\n");
} }

View File

@ -4,9 +4,12 @@
#define AMOUNT_OF_TESTS 400000 #define AMOUNT_OF_TESTS 400000
#define test_hashf(hasht, hashf, tests_n)\ char __buf[]="iojihiojopijiugbjmoihftytryfdrh";
#define test_hashfunc(hasht, hashf, tests_n)\
optime(#hashf,1,({\ optime(#hashf,1,({\
printf("\e[94mfunction: " #hashf "\n");\ printf("\e[94mfunction: \e[92m" #hashf "\n");\
printf("\e[94mhash of \"%s\": \e[92m%x\n",__buf, hashf(__buf,cptr_length(__buf)));\
Autoarr(hasht)* hashes=Autoarr_create(hasht,512,32768);\ Autoarr(hasht)* hashes=Autoarr_create(hasht,512,32768);\
uint32 collisions=0;\ uint32 collisions=0;\
for(uint32 i=0;i<tests_n;i++){\ for(uint32 i=0;i<tests_n;i++){\
@ -22,16 +25,13 @@
if(col) collisions++;\ if(col) collisions++;\
else Autoarr_add(hashes,h);\ else Autoarr_add(hashes,h);\
}\ }\
printf("\e[92m%u collisions detected per %u numbers\n", collisions, tests_n);\ printf("\e[93m%u \e[94mcollisions detected in %u hashes\n", collisions, tests_n);\
})) }))
void test_hash_collisions(){ void test_hash_functions(){
optime("test_hash_collisions",1,({ optime("test_hash_functions",1,({
printf("\e[96m--------[test_hash_collisions]--------\n"); printf("\e[96m--------[test_hash_functions]---------\n");
char buf[]="iojihiojopijiugbjmoihftytryfdrh"; test_hashfunc(uint32, hashb_crc32, 10000);
printf("\e[92mhashb_crc32: %x\n", hashb_crc32(buf,cptr_length(buf))); test_hashfunc(uint32, hashb_sdbm32, 10000);
printf("\e[92mhashb_sdbm32: %x\n", hashb_sdbm32(buf,cptr_length(buf)));
test_hashf(uint32, hashb_crc32, 20000);
test_hashf(uint32, hashb_sdbm32, 20000);
})); }));
} }

View File

@ -12,7 +12,7 @@ void test_string();
void test_dtsod(); void test_dtsod();
void test_safethrow(); void test_safethrow();
void test_autoarr2(); void test_autoarr2();
void test_hash_collisions(); void test_hash_functions();
#if __cplusplus #if __cplusplus
} }
#endif #endif