7 KSORT_INIT_GENERIC(int)
9 int main(int argc
, char *argv
[])
14 if (argc
> 1) N
= atoi(argv
[1]);
15 array
= (int*)malloc(sizeof(int) * N
);
18 for (i
= 0; i
< N
; ++i
) array
[i
] = (int)lrand48();
20 x
= ks_ksmall(int, N
, array
, 10500);
22 fprintf(stderr
, "ksmall [%d]: %.3lf\n", x
, (double)(t2
-t1
)/CLOCKS_PER_SEC
);
25 for (i
= 0; i
< N
; ++i
) array
[i
] = (int)lrand48();
27 ks_introsort(int, N
, array
);
29 fprintf(stderr
, "introsort [%d]: %.3lf\n", array
[10500], (double)(t2
-t1
)/CLOCKS_PER_SEC
);
30 for (i
= 0; i
< N
-1; ++i
) {
31 if (array
[i
] > array
[i
+1]) {
32 fprintf(stderr
, "Bug in introsort!\n");
38 { // test unaligned ksmall
42 a
= malloc(N
* sizeof(int) + 1);
44 for (i
= 0; i
< N
; ++i
) b
[i
] = (int)lrand48();
46 ks_introsort(int, N
, b
);
48 fprintf(stderr
, "introsort [%d]: %.3lf (unaligned: 0x%lx) \n", b
[10500], (double)(t2
-t1
)/CLOCKS_PER_SEC
, (size_t)b
);
53 ks_introsort(int, N
, array
);
55 fprintf(stderr
, "introsort (sorted): %.3lf\n", (double)(t2
-t1
)/CLOCKS_PER_SEC
);
58 for (i
= 0; i
< N
; ++i
) array
[i
] = (int)lrand48();
60 ks_combsort(int, N
, array
);
62 fprintf(stderr
, "combsort: %.3lf\n", (double)(t2
-t1
)/CLOCKS_PER_SEC
);
63 for (i
= 0; i
< N
-1; ++i
) {
64 if (array
[i
] > array
[i
+1]) {
65 fprintf(stderr
, "Bug in combsort!\n");
71 for (i
= 0; i
< N
; ++i
) array
[i
] = (int)lrand48();
73 ks_mergesort(int, N
, array
, 0);
75 fprintf(stderr
, "mergesort: %.3lf\n", (double)(t2
-t1
)/CLOCKS_PER_SEC
);
76 for (i
= 0; i
< N
-1; ++i
) {
77 if (array
[i
] > array
[i
+1]) {
78 fprintf(stderr
, "Bug in mergesort!\n");
84 ks_mergesort(int, N
, array
, 0);
86 fprintf(stderr
, "mergesort (sorted): %.3lf\n", (double)(t2
-t1
)/CLOCKS_PER_SEC
);
89 for (i
= 0; i
< N
; ++i
) array
[i
] = (int)lrand48();
91 ks_heapmake(int, N
, array
);
92 ks_heapsort(int, N
, array
);
94 fprintf(stderr
, "heapsort: %.3lf\n", (double)(t2
-t1
)/CLOCKS_PER_SEC
);
95 for (i
= 0; i
< N
-1; ++i
) {
96 if (array
[i
] > array
[i
+1]) {
97 fprintf(stderr
, "Bug in heapsort!\n");