test_hash_functions
This commit is contained in:
parent
11875856c2
commit
d525270443
@ -1,14 +1,14 @@
|
||||
#include "tests.h"
|
||||
|
||||
void test_all(){
|
||||
// test_autoarr();
|
||||
// test_string();
|
||||
// test_safethrow();
|
||||
// test_searchtree();
|
||||
// test_hashtable();
|
||||
// test_dtsod();
|
||||
// test_autoarr2();
|
||||
test_hash_collisions();
|
||||
test_autoarr();
|
||||
test_string();
|
||||
test_safethrow();
|
||||
test_searchtree();
|
||||
test_hashtable();
|
||||
test_dtsod();
|
||||
test_autoarr2();
|
||||
test_hash_functions();
|
||||
printf("\e[96m---------------------------------------\e[0m\n");
|
||||
}
|
||||
|
||||
|
||||
@ -4,9 +4,12 @@
|
||||
|
||||
#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,({\
|
||||
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);\
|
||||
uint32 collisions=0;\
|
||||
for(uint32 i=0;i<tests_n;i++){\
|
||||
@ -22,16 +25,13 @@
|
||||
if(col) collisions++;\
|
||||
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(){
|
||||
optime("test_hash_collisions",1,({
|
||||
printf("\e[96m--------[test_hash_collisions]--------\n");
|
||||
char buf[]="iojihiojopijiugbjmoihftytryfdrh";
|
||||
printf("\e[92mhashb_crc32: %x\n", hashb_crc32(buf,cptr_length(buf)));
|
||||
printf("\e[92mhashb_sdbm32: %x\n", hashb_sdbm32(buf,cptr_length(buf)));
|
||||
test_hashf(uint32, hashb_crc32, 20000);
|
||||
test_hashf(uint32, hashb_sdbm32, 20000);
|
||||
void test_hash_functions(){
|
||||
optime("test_hash_functions",1,({
|
||||
printf("\e[96m--------[test_hash_functions]---------\n");
|
||||
test_hashfunc(uint32, hashb_crc32, 10000);
|
||||
test_hashfunc(uint32, hashb_sdbm32, 10000);
|
||||
}));
|
||||
}
|
||||
@ -12,7 +12,7 @@ void test_string();
|
||||
void test_dtsod();
|
||||
void test_safethrow();
|
||||
void test_autoarr2();
|
||||
void test_hash_collisions();
|
||||
void test_hash_functions();
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif
|
||||
Loading…
Reference in New Issue
Block a user