X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;ds=sidebyside;f=lib%2Fsorter%2Fsort-test.c;h=71c6a12ff75790b82bfeb6d2c216352fe94ea6fa;hb=f08c91407f0ccdcc07cee4a49ccb4bddd4c35988;hp=9a822d141847037182f8a40cf3553bd8a16d8904;hpb=66b0f5843d272887ceb09b0d2d339f3cec10eca7;p=libucw.git diff --git a/lib/sorter/sort-test.c b/lib/sorter/sort-test.c index 9a822d14..71c6a12f 100644 --- a/lib/sorter/sort-test.c +++ b/lib/sorter/sort-test.c @@ -24,6 +24,7 @@ /*** Time measurement ***/ static timestamp_t timer; +static uns test_id; static void start(void) @@ -36,7 +37,7 @@ static void stop(void) { sync(); - log(L_INFO, "Test took %.3fs", get_timer(&timer) / 1000.); + msg(L_INFO, "Test %d took %.3fs", test_id, get_timer(&timer) / 1000.); } /*** Simple 4-byte integer keys ***/ @@ -60,7 +61,7 @@ test_int(int mode, u64 size) { uns N = size ? nextprime(MIN(size/4, 0xffff0000)) : 0; uns K = N/4*3; - log(L_INFO, ">>> Integers (%s, N=%u)", ((char *[]) { "increasing", "decreasing", "random" })[mode], N); + msg(L_INFO, ">>> Integers (%s, N=%u)", ((char *[]) { "increasing", "decreasing", "random" })[mode], N); struct fastbuf *f = bopen_tmp(65536); for (uns i=0; i>> Counted integers (%s, N=%u, mult=%u)", ((char *[]) { "increasing", "decreasing", "random" })[mode], N, mult); + msg(L_INFO, ">>> Counted integers (%s, N=%u, mult=%u)", ((char *[]) { "increasing", "decreasing", "random" })[mode], N, mult); struct fastbuf *f = bopen_tmp(65536); for (uns m=0; mhash[i], y->hash[i]); + COMPARE(x->hash[0], y->hash[0]); + COMPARE(x->hash[1], y->hash[1]); + COMPARE(x->hash[2], y->hash[2]); + COMPARE(x->hash[3], y->hash[3]); return 0; } @@ -205,7 +207,7 @@ static void test_hashes(int mode, u64 size) { uns N = MIN(size / sizeof(struct key3), 0xffffffff); - log(L_INFO, ">>> Hashes (%s, N=%u)", ((char *[]) { "increasing", "decreasing", "random" })[mode], N); + msg(L_INFO, ">>> Hashes (%s, N=%u)", ((char *[]) { "increasing", "decreasing", "random" })[mode], N); struct key3 k, lastk; struct fastbuf *f = bopen_tmp(65536); @@ -323,7 +325,7 @@ test_strings(uns mode, u64 size) { uns avg_item_size = KEY4_MAX/2 + 4 + (mode ? 128 : 0); uns N = MIN(size / avg_item_size, 0xffffffff); - log(L_INFO, ">>> Strings %s(N=%u)", (mode ? "with data " : ""), N); + msg(L_INFO, ">>> Strings %s(N=%u)", (mode ? "with data " : ""), N); srand(1); struct key4 k, lastk; @@ -417,7 +419,7 @@ static void s5_write_merged(struct fastbuf *f, struct key5 **keys, void **data, s5m_sort(m, a); keys[0]->cnt = m; bwrite(f, keys[0], sizeof(struct key5)); - bwrite(f, a, 4*m); /* FIXME: Might overflow here */ + bwrite(f, a, 4*m); } static void s5_copy_merged(struct key5 **keys, struct fastbuf **data, uns n, struct fastbuf *dest) @@ -452,13 +454,10 @@ static inline int s5p_lt(struct s5_pair x, struct s5_pair y) return 0; } -/* FIXME: Use smarter internal sorter when it's available */ #define ASORT_PREFIX(x) s5p_##x #define ASORT_KEY_TYPE struct s5_pair -#define ASORT_ELT(i) ary[i] #define ASORT_LT(x,y) s5p_lt(x,y) -#define ASORT_EXTRA_ARGS , struct s5_pair *ary -#include "lib/arraysort.h" +#include "lib/sorter/array.h" static int s5_presort(struct fastbuf *dest, void *buf, size_t bufsize) { @@ -469,7 +468,7 @@ static int s5_presort(struct fastbuf *dest, void *buf, size_t bufsize) n++; if (!n) return 0; - s5p_sort(n, a); + s5p_sort(a, n); uns i = 0; while (i < n) { @@ -514,7 +513,7 @@ test_graph(uns mode, u64 size) uns N = 3; while ((u64)N*(N+2)*4 < size) N = nextprime(N); - log(L_INFO, ">>> Graph%s (N=%u)", (mode ? "" : " with custom presorting"), N); + msg(L_INFO, ">>> Graph%s (N=%u)", (mode ? "" : " with custom presorting"), N); s5_N = N; s5_K = N/4*3; s5_L = N/3*2; @@ -560,11 +559,53 @@ test_graph(uns mode, u64 size) bclose(f); } +/*** Simple 8-byte integer keys ***/ + +struct key6 { + u64 x; +}; + +#define SORT_KEY_REGULAR struct key6 +#define SORT_PREFIX(x) s6_##x +#define SORT_INPUT_FB +#define SORT_OUTPUT_FB +#define SORT_UNIQUE +#define SORT_INT64(k) (k).x + +#include "lib/sorter/sorter.h" + +static void +test_int64(int mode, u64 size) +{ + u64 N = size ? nextprime(MIN(size/8, 0xffff0000)) : 0; + u64 K = N/4*3; + msg(L_INFO, ">>> 64-bit integers (%s, N=%llu)", ((char *[]) { "increasing", "decreasing", "random" })[mode], (long long)N); + + struct fastbuf *f = bopen_tmp(65536); + for (u64 i=0; i