2 * UCW Library -- Universal Array Sorter Test and Benchmark
4 * (c) 2003 Martin Mares <mj@ucw.cz>
6 * This software may be freely distributed and used according to the terms
7 * of the GNU Lesser General Public License.
15 #define N 4000037 /* a prime */
22 static struct elt array[N];
24 #define ASORT_KEY_TYPE u32
25 #define ASORT_ELT(i) array[i].key
26 #define ASORT_SWAP(i,j) do { struct elt e=array[j]; array[j]=array[i]; array[i]=e; } while(0)
28 static void generate(void)
37 ASORT_ELT(i) = (i ? ASORT_ELT(i-1)+1944833754 : 3141592) % N;
41 static int errors = 0;
43 static void check(void)
47 if (ASORT_ELT(i) != i)
49 printf("error at pos %d: %08x != %08x\n", i, ASORT_ELT(i), i);
54 static int qs_comp(const struct elt *X, const struct elt *Y)
58 else if (X->key > Y->key)
64 #define ASORT_PREFIX(x) as_##x
65 #include "ucw/sorter/array-simple.h"
73 qsort(array, N, sizeof(array[0]), (int (*)(const void *, const void *)) qs_comp);
74 printf("qsort: %d ms\n", get_timer(&timer));
79 printf("asort: %d ms\n", get_timer(&timer));