X-Git-Url: https://git.kengrimes.com/?p=henge%2Fapc.git;a=blobdiff_plain;f=src%2Ftestston.c;h=0c0fc19db1b7b3a210e10e5730ff721abe80ccca;hp=71c01102489e50ca383fc74fb361a09ff89fc49c;hb=6bcbbd2bd3710e13cad79b6822ef93e796d5e105;hpb=b0013aa7f2237fb88daf3f2ba856c8cdfe222fa2 diff --git a/src/testston.c b/src/testston.c index 71c0110..0c0fc19 100644 --- a/src/testston.c +++ b/src/testston.c @@ -1,16 +1,122 @@ -#include "../ston/ston.h" #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[]) -{ ston_ht ht; +{ 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); */ - if ((ht = ston_ht32_new(2,1,0,malloc)) == NULL) - fprintf(stderr,"Could not allocate ht32\n"); - ston_ht32_insertx(ht,50,1,200); - htval = ston_ht32_entry(ht,50,1); - printf("[50][1] = %i\n",*htval); - free(ht); - return 0; + printf("\nDONE\n"); }