#include //malloc #include //print #include //memcpy #include //clock #include "../ston/ston.h" #define XXH_PRIVATE_API #include "../xxHash/xxhash.h" /* ansi terminal colors */ #define RED "\x1b[31m" #define GREEN "\x1b[32m" #define YELLOW "\x1b[33m" #define BLUE "\x1b[34m" #define MAGENTA "\x1b[35m" #define CYAN "\x1b[36m" #define CLRC "\x1b[0m" //clear current color #define CLRCN CLRC"\n" #define startclock(_STR) do { \ start = clock(); \ printf(_STR": "); \ } while (0) #define startclockf(_STR,...) do { \ start = clock(); \ printf(_STR": ",__VA_ARGS__); \ } while (0) #define endclock() do { \ end = clock(); \ printf("%5f",(end - start)/(double)CLOCKS_PER_SEC); \ } while (0) #define endclockn() do { \ end = clock(); \ printf("%5f\n",(end - start)/(double)CLOCKS_PER_SEC); \ } while (0) #define $($)#$ #define do_test(_COL,_COUNT,_HT,_FREE,_HTNEW,_HTINSERT,_HTROW,_SEED) do { \ printf("[ " $(_HT) " ] "); \ columns = _COL; \ count = _COUNT; \ _HT = _HTNEW; \ startclockf("Filling " $(_HT) " with %i entries",count); \ while (count--) \ { key = XXH32(&count,4,_SEED); \ val[0] = key; \ for (i = 0; i < columns; i++) \ val[i] = key - i; \ _HTINSERT(_HT,key,val,0,columns); \ } \ endclockn(); \ count = _COUNT; \ fail = 0; \ startclock("Reading entries"); \ while (count--) \ { key = XXH32(&count,4,_SEED); \ htval = _HTROW(_HT,key); \ if (htval == NULL) \ { fail++; \ printf("Row returned null\n"); \ break; \ } \ if (*htval != key) \ fail++; \ for (i = 1; i < columns; i++) \ if (htval[i] != key - i) \ fail++; \ } \ endclock(); \ if (fail) \ printf(RED"\nFAIL"CLRC"(%i)\n", fail); \ else \ printf(GREEN"\nPASS"CLRCN); \ _FREE(_HT); \ } while (0) int main(int argc, char* argv[]) { static ston_ht ht; static ston_dht dht; uint32_t val[255], key; uint32_t* htval; size_t i; uint16_t columns; int fail; clock_t start, end; int count; printf("\nLow usage:\n"); do_test(2,200,ht,free,ston_ht32_new(2,200,0,malloc),ston_ht32_insertx,ston_ht32_row,0xCEED); do_test(5,200,ht,free,ston_ht32_new(5,200,0,malloc),ston_ht32_insertx,ston_ht32_row,0xCEED); do_test(2,200,dht,ston_dht_free,ston_dht32_new(2,malloc,free),ston_dht32_insertx,ston_dht32_row,0xCEED); do_test(5,200,dht,ston_dht_free,ston_dht32_new(5,malloc,free),ston_dht32_insertx,ston_dht32_row,0xCEED); printf("\nLow-mid usage:\n"); do_test(2,10000,ht,free,ston_ht32_new(2,10000,0,malloc),ston_ht32_insertx,ston_ht32_row,0xCEED); do_test(5,10000,ht,free,ston_ht32_new(5,10000,0,malloc),ston_ht32_insertx,ston_ht32_row,0xCEED); do_test(2,10000,dht,ston_dht_free,ston_dht32_new(2,malloc,free),ston_dht32_insertx,ston_dht32_row,0xCEED); do_test(5,10000,dht,ston_dht_free,ston_dht32_new(5,malloc,free),ston_dht32_insertx,ston_dht32_row,0xCEED); printf("\nMid usage:\n"); do_test(2,500000,ht,free,ston_ht32_new(2,500000,0,malloc),ston_ht32_insertx,ston_ht32_row,0xCEED); do_test(5,500000,ht,free,ston_ht32_new(5,500000,0,malloc),ston_ht32_insertx,ston_ht32_row,0xCEED); do_test(2,500000,dht,ston_dht_free,ston_dht32_new(2,malloc,free),ston_dht32_insertx,ston_dht32_row,0xCEED); do_test(5,500000,dht,ston_dht_free,ston_dht32_new(5,malloc,free),ston_dht32_insertx,ston_dht32_row,0xCEED); printf("\nMid-high usage:\n"); do_test(2,9000000,ht,free,ston_ht32_new(2,9000000,0,malloc),ston_ht32_insertx,ston_ht32_row,0xCEED); do_test(5,9000000,ht,free,ston_ht32_new(5,9000000,0,malloc),ston_ht32_insertx,ston_ht32_row,0xCEED); do_test(2,9000000,dht,ston_dht_free,ston_dht32_new(2,malloc,free),ston_dht32_insertx,ston_dht32_row,0xCEED); do_test(2,9000000,dht,ston_dht_free,ston_dht32_new(5,malloc,free),ston_dht32_insertx,ston_dht32_row,0xCEED); /* printf("\nHigh usage:\n"); */ /* do_test(2,90000000,ht,free,ston_ht32_new(2,90000000,0,malloc),ston_ht32_insertx,ston_ht32_row,0xCEED); */ /* do_test(2,90000000,dht,ston_dht_free,ston_dht32_new(2,malloc,free),ston_dht32_insertx,ston_dht32_row,0xCEED); */ /* printf("\nHuge usage:\n"); */ /* do_test(2,100000000,ht,free,ston_ht32_new(2,100000000,0,malloc),ston_ht32_insertx,ston_ht32_row,0xCEED); */ /* do_test(2,100000000,dht,ston_dht_free,ston_dht32_new(2,malloc,free),ston_dht32_insertx,ston_dht32_row,0xCEED); */ printf("\nDONE\n"); }