dht reimplemented, 66% net execution time overall
[henge/apc.git] / src / testston.c
1 #include <stdlib.h> //malloc
2 #include <stdio.h> //print
3 #include <string.h> //memcpy
4 #include <time.h> //clock
5 #include "../ston/ston.h"
6 #define XXH_PRIVATE_API
7 #include "../xxHash/xxhash.h"
8
9 /* ansi terminal colors */
10 #define RED "\x1b[31m"
11 #define GREEN "\x1b[32m"
12 #define YELLOW "\x1b[33m"
13 #define BLUE "\x1b[34m"
14 #define MAGENTA "\x1b[35m"
15 #define CYAN "\x1b[36m"
16 #define CLRC "\x1b[0m" //clear current color
17 #define CLRCN CLRC"\n"
18
19 #define startclock(_STR) do { \
20 start = clock(); \
21 printf(_STR": "); \
22 } while (0)
23
24 #define startclockf(_STR,...) do { \
25 start = clock(); \
26 printf(_STR": ",__VA_ARGS__); \
27 } while (0)
28
29 #define endclock() do { \
30 end = clock(); \
31 printf("%5f",(end - start)/(double)CLOCKS_PER_SEC); \
32 } while (0)
33
34 #define endclockn() do { \
35 end = clock(); \
36 printf("%5f\n",(end - start)/(double)CLOCKS_PER_SEC); \
37 } while (0)
38
39 #define $($)#$
40 #define do_test(_COL,_COUNT,_HT,_FREE,_HTNEW,_HTINSERT,_HTROW,_SEED) do { \
41 printf("[ " $(_HT) " ] "); \
42 columns = _COL; \
43 count = _COUNT; \
44 _HT = _HTNEW; \
45 startclockf("Filling " $(_HT) " with %i entries",count); \
46 while (count--) \
47 { key = XXH32(&count,4,_SEED); \
48 val[0] = key; \
49 for (i = 0; i < columns; i++) \
50 val[i] = key - i; \
51 _HTINSERT(_HT,key,val,0,columns); \
52 } \
53 endclockn(); \
54 count = _COUNT; \
55 fail = 0; \
56 startclock("Reading entries"); \
57 while (count--) \
58 { key = XXH32(&count,4,_SEED); \
59 htval = _HTROW(_HT,key); \
60 if (htval == NULL) \
61 { fail++; \
62 printf("Row returned null\n"); \
63 break; \
64 } \
65 if (*htval != key) \
66 fail++; \
67 for (i = 1; i < columns; i++) \
68 if (htval[i] != key - i) \
69 fail++; \
70 } \
71 endclock(); \
72 if (fail) \
73 printf(RED"\nFAIL"CLRC"(%i)\n", fail); \
74 else \
75 printf(GREEN"\nPASS"CLRCN); \
76 _FREE(_HT); \
77 } while (0)
78
79 int main(int argc, char* argv[])
80 { static ston_ht ht;
81 static ston_dht dht;
82 uint32_t val[255], key;
83 uint32_t* htval;
84 size_t i;
85 uint16_t columns;
86 int fail;
87 clock_t start, end;
88 int count;
89 printf("\nLow usage:\n");
90 do_test(2,200,ht,free,ston_ht32_new(2,200,0,malloc),ston_ht32_insertx,ston_ht32_row,0xCEED);
91 do_test(5,200,ht,free,ston_ht32_new(5,200,0,malloc),ston_ht32_insertx,ston_ht32_row,0xCEED);
92 do_test(2,200,dht,ston_dht_free,ston_dht32_new(2,malloc,free),ston_dht32_insertx,ston_dht32_row,0xCEED);
93 do_test(5,200,dht,ston_dht_free,ston_dht32_new(5,malloc,free),ston_dht32_insertx,ston_dht32_row,0xCEED);
94
95 printf("\nLow-mid usage:\n");
96 do_test(2,10000,ht,free,ston_ht32_new(2,10000,0,malloc),ston_ht32_insertx,ston_ht32_row,0xCEED);
97 do_test(5,10000,ht,free,ston_ht32_new(5,10000,0,malloc),ston_ht32_insertx,ston_ht32_row,0xCEED);
98 do_test(2,10000,dht,ston_dht_free,ston_dht32_new(2,malloc,free),ston_dht32_insertx,ston_dht32_row,0xCEED);
99 do_test(5,10000,dht,ston_dht_free,ston_dht32_new(5,malloc,free),ston_dht32_insertx,ston_dht32_row,0xCEED);
100
101 printf("\nMid usage:\n");
102 do_test(2,500000,ht,free,ston_ht32_new(2,500000,0,malloc),ston_ht32_insertx,ston_ht32_row,0xCEED);
103 do_test(5,500000,ht,free,ston_ht32_new(5,500000,0,malloc),ston_ht32_insertx,ston_ht32_row,0xCEED);
104 do_test(2,500000,dht,ston_dht_free,ston_dht32_new(2,malloc,free),ston_dht32_insertx,ston_dht32_row,0xCEED);
105 do_test(5,500000,dht,ston_dht_free,ston_dht32_new(5,malloc,free),ston_dht32_insertx,ston_dht32_row,0xCEED);
106
107 printf("\nMid-high usage:\n");
108 do_test(2,9000000,ht,free,ston_ht32_new(2,9000000,0,malloc),ston_ht32_insertx,ston_ht32_row,0xCEED);
109 do_test(5,9000000,ht,free,ston_ht32_new(5,9000000,0,malloc),ston_ht32_insertx,ston_ht32_row,0xCEED);
110 do_test(2,9000000,dht,ston_dht_free,ston_dht32_new(2,malloc,free),ston_dht32_insertx,ston_dht32_row,0xCEED);
111 do_test(2,9000000,dht,ston_dht_free,ston_dht32_new(5,malloc,free),ston_dht32_insertx,ston_dht32_row,0xCEED);
112
113 /* printf("\nHigh usage:\n"); */
114 /* do_test(2,90000000,ht,free,ston_ht32_new(2,90000000,0,malloc),ston_ht32_insertx,ston_ht32_row,0xCEED); */
115 /* do_test(2,90000000,dht,ston_dht_free,ston_dht32_new(2,malloc,free),ston_dht32_insertx,ston_dht32_row,0xCEED); */
116
117 /* printf("\nHuge usage:\n"); */
118 /* do_test(2,100000000,ht,free,ston_ht32_new(2,100000000,0,malloc),ston_ht32_insertx,ston_ht32_row,0xCEED); */
119 /* do_test(2,100000000,dht,ston_dht_free,ston_dht32_new(2,malloc,free),ston_dht32_insertx,ston_dht32_row,0xCEED); */
120
121 printf("\nDONE\n");
122 }